Created
March 26, 2018 22:41
-
-
Save poshcodebear/af5e74a3f6ea90475c2d67bcebabd02d to your computer and use it in GitHub Desktop.
New-RandomPassword
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
function New-RandomPassword { | |
$charset = ([char]'a'..[char]'z').foreach({[char]$_}) | |
$RawPassword = '' | |
for ($i = 0; $i -lt 14; $i++) | |
{ | |
# First and last 4 are letters | |
if ($i -lt 4 -or $i -gt 9) | |
{ | |
if ($i % 2 -eq 0) | |
{ $set = $charset -match '[^aeiou]' } | |
else | |
{ $set = $charset -match '[aeiou]' } | |
} | |
else | |
{ $set = 0..9 } | |
$RawPassword += [string](Get-Random $set) | |
if ($i -eq 0) | |
{ $RawPassword = $RawPassword.ToUpper() } | |
} | |
$SecureString = ConvertTo-SecureString -AsPlainText $RawPassword -Force | |
[PSCustomObject]@{ | |
'RawPassword' = $RawPassword | |
'SecureString' = $SecureString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment