In case anyone else is looking to do the same, here is PS for the "Before creating a user" business rule I ended up using. I'm sure this could be improved on but it works for our use:
$MinimumLength = 12
# Define the URL for the word list
$WordListUrl = "https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt"
# Download the word list
try
{
$WordList = Invoke-WebRequest -Uri $WordListUrl -UseBasicParsing -ErrorAction Stop | ForEach-Object { $_.Content }
# Split the word list into an array of words
$Words = $WordList -split "`n" | ForEach-Object {
$split = $_ -split "`t"
[PSCustomObject]@{
Number = $split[0]
Word = $split[1]
}
}
# Select three random words from the list
$RandomWords = Get-Random -InputObject $Words -Count 2
# Capitalize the first letter of each word
$CapitalizedWords = $RandomWords.Word | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }
# Join the capitalized words with hyphens
$Password = $CapitalizedWords -join "-"
# Add a random digit to the end
$RandomDigit = Get-Random -Minimum 0 -Maximum 9
$Password += "-$RandomDigit"
# Ensure the password is at least 12 characters
if ($Password.Length -lt $MinimumLength)
{
$Password = ($CapitalizedWords -join "-") + "-$RandomDigit"
}
$Context.SetModifiedPropertyValue("unicodePwd", $Password)
$Context.SetNewPassword($Password)
$Context.LogMessage("Password for new user %sAMAccountName% set to $($Password)", "Information")
$Context.SendMail("%adm-InitiatorEmail%", "New Account: %sAMAccountName%", "User: %sAMAccountName%`nPass: $Password",$null)
}
catch
{
$Context.LogMessage("Error downloading word list. You will have to manually enter a first time password for this user.",2)
}