PowerShell for Windows Admins

Dec 27 2018   7:11AM GMT

Create a random string

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I often need to create a random string of characters. Here’s a simple function to achieve that:


The required length is passed as an integer parameter.  Use the range operator as a counter and in Foreach-Object generate a random number between 97 and 122.  Convert that to a char  (a=97 and z-122) and add to the array.  Join the array of chars to create the string.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: