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.
1 2 | $Assembly = Add-Type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(8,3) |
How do we know all that? With a little help from the Get-Member cmdlet (and simplified where syntax):
1 | [System.Web.Security.Membership] | Get-Member -MemberType method -Static| where name -match password |