Last Updated on
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