Last active
April 16, 2017 09:18
-
-
Save goyalmohit/da8749abac29a9c555f757df33b01db5 to your computer and use it in GitHub Desktop.
Generate random password using PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#function starts here | |
function New-RandomPassword() | |
{ | |
#specifies the default maximum no of characters to be generated for password | |
#can be override by passing parameter values while calling function | |
param( | |
[int]$maxChars=8 | |
) | |
#specifies a new empty password | |
$newPassword = "" | |
#defines random function | |
$rand = New-Object System.Random | |
#generates random password | |
0..$maxChars | ForEach-Object {$newPassword += [char]$rand.Next(33,126)} | |
return $newPassword | |
} | |
#function ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment