Make Life EasierMicrosoftUncategorized

PowerShell – Generate password from word list and numbers for AD User

I’ve always used a random password generator for some sub accounts that change weekly via task scheduler. The issue with that is the lower case l and 1’s depending on the systems font look very similar resulting in tickets saying the password doesn’t work.

I’ve patched together this script from a few online sources and use this in Adaxes.

This script will:

  • Pull words from $WordList
  • Add a random number to the end of the password between 1000-9999
  • Email the password to the specified email address.

$WordList = 'Ocean','Mountain','Desert','Oregon','Sunbreak','Pacific','Northwest','Timber','Salmon','Cougar','Deer','Turtle'

Function Create-Password
{ 
  # query the smaller list of words for single entry (2 times)
  $word1 = $WordList | Sort-Object {Get-Random} -unique | select -first 1
  $word2 = $WordList | Sort-Object {Get-Random} -unique | select -first 1

  # create random digits
  $number1 = Get-Random -Minimum 1000 -Maximum 9999
  
  # concatenante and return new random password
  return ($word1) + ($word2) + $number1
}

$PasswordGen = Create-Password


$password = "$PasswordGen" # TODO: modify me
$to = "CHANGEME@changeme.com" # TODO: modify me
$subject = "Password Reset for %fullname%" # TODO: modify me
$messageText = @"
<p><span style="font-size:16px;"><span style="font-family:times new roman,times,serif;">Password has been reset for %fullname%.</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:Consolas;">New password: $PasswordGen <br />
Username: %username%</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:times new roman,times,serif;">Please do not reply to this e-mail, it has been sent to you for notification purposes only.</span></span></p>
"@ # TODO: modify me

$Context.TargetObject.SetPassword($password)
$Context.SendMail($to, $subject, $NULL, $messageText)

Show More

Cory Fiala

Technology and outdoor enthusiast. Currently the sole systems administrator for a local K-12 school district with 800+ staff and 5,500+ students. I support windows servers (2012R2-2022), Linux systems (FreeBSD and Ubuntu), along with vSphere (4 node cluster). Total is almost 60 virtual machines and 8 physical servers. This doesn't include my personal homelab.

Related Articles

Leave a Reply

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

Back to top button