Hi All
I am using below code to generate random password .
$pwd = [System.Web.Security.Membership]::GeneratePassword(15,2)
random password generated from above function is b}0-ad.GqCz:e>!
how can i avoid generating special characters like "{" , "}" , please suggest.
i used below function and it worked thanks
Function New-SecurePassword {
$Password = "!?@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray()
($Password | Get-Random -Count 8) -Join ''
}
tonyd
June 23, 2020, 11:30am
3
I think all you can do is delete or replace those characters after generating the password. The GeneratePassword method only accepts 2 arguments, length and number of non alpha numeric characters.
This link might help:
https://stackoverflow.com/questions/30215047/how-to-remove-curly-braces-from-string-in-powershell
There are many homegrown password generators. You could take this fine example and just remove the characters/charactersets you don’t want.
https://gist.github.com/Jaykul/5cb0410abd40672707faf67549404ea8