Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Last active April 16, 2017 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalmohit/da8749abac29a9c555f757df33b01db5 to your computer and use it in GitHub Desktop.
Save goyalmohit/da8749abac29a9c555f757df33b01db5 to your computer and use it in GitHub Desktop.
Generate random password using PowerShell
#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