In this post we will see the simplest way I came across to generate random passwords using PowerShell. There are other methods available with large features set but this one is good enough for most requirements
First let us look at the simplest way. The GeneratePassword method of System.Web.Security.Membership class simplifies the password generation.
Add-Type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(8,3)
As you can see from the above screen, these 2 simple lines of code generated a random password of length 8.
The GeneratePassword() method takes 2 arguments. First one is length of password and second one is number of non-alphanumerics you want in the random password. In my example, I have provided 8 as password length and 3 as number of non-alphanumeric characters I need.
You can use this approach to generate as many number of random passwords you want. Look at the below example.
1..10 | % { [System.Web.Security.Membership]::GeneratePassword(8,3) }
There are other ways available as well. I am sharing some of the links that I came across.
- https://activedirectoryfaq.com/2017/08/creating-individual-random-passwords/
- https://gallery.technet.microsoft.com/scriptcenter/Password-Generator-using-0f99f008
- https://4sysops.com/archives/generate-complex-passwords-with-powershell/
- https://gist.github.com/indented-automation/2093bd088d59b362ec2a5b81a14ba84e
Hope this article helps. Let me know if you come across any easy and better way.