Windows PowerShell 4.0 Examples – How to Generate Complex Password

There is no built-in cmdlet to generate a password, but we can leverage a vast number of .NET Framework classes. System.Web.Security.Membership class has a static method GeneratePassword(). First, we need to load an assembly containing this class, and then we use GeneratePassword() to define password length and a number of non-alphanumeric characters.

$Assembly = Add-Type -AssemblyName System.Web

How do we know all that? With a little help from the Get-Member cmdlet (and simplified where syntax):

[System.Web.Security.Membership] | Get-Member -MemberType method -Static| where name -match password

About the author

Lima is the visual nautical indicator for "stop instantly."

Leave a Reply