Random Password Generator

Define the password length and you’ll get a secure, randomly generated password.

1
2
$pwdLength = 15
$rngPWD = ([char[]]([char]33..[char]95) + ([char[]]([char]97..[char]126)) + 0..9 | sort {Get-Random})[0..$pwdLength] -join ''

If you need to use this for Active Directory user creation, you can convert the string to a securestring and use it like so:

1
2
$regPWDsec =  ConvertTo-SecureString $rngPWD -AsPlainText -Force
New-ADUser -Server 'blah.blah' -Path "OU=Blah,DC=blah,DC=blah" -AccountPassword $rngPWDsec -<all other defined parameters>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.