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
2 comments
Hide comments