This snippet generates a random password starting with 2 digits or capital letters following by 16 random characters with ASCII codes between 33 and 126 and ending with two random lower case letters
(48..57)+(65..90) | Get-Random -Count 2 | % -begin {$PwdStr='';} -process {$PwdStr+=[char]$_}
(33..126) | Get-Random -Count 16 | % -process {$PwdStr+=[char]$_}
(97..122) | Get-Random -Count 2 | % -process {$PwdStr+=[char]$_} -end {$PwdStr}
Exclude XML escape characters (as well as '\' and '/') from the passwords
(33..126) | ? {([int][char]'!',[int][char]'<',[int][char]'>', [int][char]'\',[int][char]'/',[int][char]'"',[int][char]"'", [int][char]'&' ) -notcontains $_} `
| Get-Random -Count 44 | % -begin {$PwdStr=''} -process {$PwdStr+=[char]$_} -end {$pwdStr}
Password from a string -->
$("!@#$%*_-=+.:;[]{}0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").ToCharArray() | Get-Random -Count 22 | % -begin {$PwdStr='';} -process {$PwdStr+=$_} -end {$pwdstr}
Comments
Post a Comment