How generate passwords in PowerShell

Published on Thursday, 2 November 2017

Simple Password Generator

If you ever find the need to create a random password there is actually a part of .NET that can do it for you. You can all it from PowerShell with the following 2 lines:

using assembly System.Web
[System.Web.Security.Membership]::GeneratePassword(8,1)

The way this function works is pretty simple.

OverloadDefinitions
-------------------
static string GeneratePassword(int length, int numberOfNonAlphanumericCharacters)

As you can see the first parameter is how long the password is and the second is how many non alphanumeric characters to use.