Last active
October 12, 2015 06:48
-
-
Save xoner/3986820 to your computer and use it in GitHub Desktop.
Generate passwords in powershell throuht System.Web.Security.Membership
This file contains 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
# You must load the System.Web assembly to your powershell session to make this script work. | |
[Reflection.Assembly]::LoadWithPartialName('System.Web') | |
function GenPassword | |
{ | |
Param( | |
[int] $PasswordLength = 0, | |
[ValidateSet("low", "medium", "high")] | |
[string] $PasswordComplexity = "medium" | |
) | |
$lPasswordLength = 0 | |
$lNonAlphanumeric = 0 | |
switch ($PasswordComplexity) | |
{ | |
"low" | |
{ | |
if($PasswordLength -gt 0) | |
{ | |
$lPasswordLength = $PasswordLength; | |
} | |
else | |
{ | |
$lPasswordLength = 8 | |
} | |
$lNonAlphanumeric = 0 | |
} | |
"medium" | |
{ | |
if ($PasswordLength -ge 2) | |
{ | |
$lPasswordLength = $PasswordLength; | |
} | |
else | |
{ | |
$lPasswordLength = 16 | |
} | |
$lNonAlphanumeric = 2 | |
} | |
"high" | |
{ | |
if($PasswordLength -ge 4) | |
{ | |
$lPasswordLength = $PasswordLength | |
} | |
else | |
{ | |
$lPasswordLength = 32 | |
} | |
$lNonAlphanumeric = 4 | |
} | |
} | |
[System.Web.Security.Membership]::GeneratePassword(16,2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment