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?

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish