Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
Learn how to create a random string in PowerShell.
November 13, 2013
Q: How can I create a random password using Windows PowerShell?
A: There is no simple cmdlet to create a random string in PowerShell. However there's a System.Random object which can be used to extract values in the range of 33-126 that are the characters from the ASCII table that are valid for Windows passwords. The code below creates a 12-character new password:
$randomObj = New-Object System.Random$NewPassword=""1..12 | ForEach { $NewPassword = $NewPassword + [char]$randomObj.next(33,126) }$NewPassword
You May Also Like