Skip to content

Instantly share code, notes, and snippets.

@michaelrice136
Created March 29, 2016 13:05
Show Gist options
  • Save michaelrice136/f14d5d3f2dff56eff73c to your computer and use it in GitHub Desktop.
Save michaelrice136/f14d5d3f2dff56eff73c to your computer and use it in GitHub Desktop.
Generate a new password using PowerShell
function New-Password ($length)
{
[string]$Password = ''
[array]$lower = @('a','b','c','d','e','f','g','h','i','j','k','l','n','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
[array]$upper = @('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
[array]$symbol = @('!','"','£','$','%','^','&','*','(',')',',','.','@','#')
[array]$num = @('1','2','3','4','5','6','7','8','9','0')
[array]$rand = @($lower,$upper,$symbol,$num)
for ($i = 1; $i -lt $length+1; $i++)
{
$RandChar = Get-Random -InputObject (Get-Random -InputObject $rand)
$Password += $RandChar
}
return $Password
}
#Use New-Password 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment