Quantcast
Channel: Microsoft – JeffOps
Viewing all articles
Browse latest Browse all 120

PowerShell function to generate a random password

$
0
0

This is part of one of my AD migration scripts which I find very useful.
Whenever creating a user, I like to generate a random and complex password. The length of the password differs for each of my customers, so that’s something I define with a parameter added to this function:

Function New-RandomPassword ($Length)
{
#Usage: New-RandomPassword 8
$Random = New-Object System.Random
$RandomPassword = (-join ([char[]](33..127) | Get-Random -Count $length))
Write-Output $RandomPassword
}

Note that this one is very basic, no check in there for when both a higher- and lower case character, number and/or punctuation mark is included. For most of my customers the function above is sufficient Knipogende emoticonI Hope you find this one useful Glimlach

 

Update: Changed the script based on feedback from Shay Levy through Twitter… thanks! :-D

 

 

Post to Twitter


Viewing all articles
Browse latest Browse all 120

Trending Articles