The Multifunctioning DBA

Oct 22 2010   10:00AM GMT

Create Random Password and update AD account

Colin Smith Colin Smith Profile: Colin Smith

Tags:

Not to long ago I was asked to write a script that would create a random password and change an AD account to use that new password. The requirements were that the password be 3 uppercase letters 2 numbers and 3 lowercase letters. Here is what I did.

#Clear out all variables from last run

$newpassword = $NULL

$loops = 1..3

## Set up Random Generator

$rand = New-Object System.Random

$i = 1

$n = 1

#set up loop to generate each section of $NewPassword

foreach($number in $loops)

{

if ($i -eq 1)

{

$part = $NULL

$m = 3

$s = 65

$e = 90

}

if ($i -eq 2)

{

$part = $NULL

$m = 2

$s = 48

$e = 57

}

if ($i -eq 3)

{

$part = $NULL

$m = 3

$s = 97

$e = 122

}

$n..$m | foreach { $part = $part + [char]$rand.next($s,$e) }

$newpassword = $newpassword + $part

$i = $i + 1

Set-QADUser PNI-GUEST -UserPassword $newpassword

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: