One-Liner: Generate a Random Password
Always learning. Forever delighted. Happily surprised.
That's using PowerShell for you... well, me.
The other week one of my customers showed me this little beauty:
[System.Web.Security.Membership]::GeneratePassword(20,5)
The GeneratePassword static method accepts two values: the first parameter is the number of characters in the generated password; the second parameter is the number of non-alphanumeric characters to include.
With the above one-liner we get a 20 character password with 5 non-alphanumeric characters. For example:
This has replaced the lengthy New-Password function I had in my $profile...
Comments
- Anonymous
February 02, 2016
I'm missing something, running PS v4.0 but...
Unable to find type [System.Web.Security.Membership]. Make sure that the assembly that contains this type is loaded.
Clue pls! - Anonymous
February 05, 2016
Let me take a look-see... - Anonymous
March 31, 2016
The comment has been removed - Anonymous
June 13, 2016
Thank you, this was very useful.