Q. What's a good way to create a secure, random password in PowerShell?

Q. What's a good way to create a secure, random password in PowerShell? A. Previously, I explained how to create a password using random characters generated by the System.Random object, butthis may not be secure enough.

ITPro Today

September 15, 2015

1 Min Read
Q. What's a good way to create a secure, random password in PowerShell?

Q. What's a good way to create a secure, random password in PowerShell?

A. Previously, I explained how to create a password using random characters generated by the System.Random object, but this may not be secure enough.

So try this method: Use the GeneratePassword method of System.Web.Security.Membership, which enables a number of characters for the new password to be specified and the number of special characters that are required within the new password. Here's where this is documented.

To use this in PowerShell use:

Add-Type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(16,2)

You can save the output to a variable then use as needed.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like