Hopefully the blog does not mundge the code… Self explanatory I hope…
Import-Module activedirectory
# Based on email addresses in file, sets password to common or predefined (choose below) and enable accounts
#
#format of CSV:
#
#importfile.csv
#email,password
#First.Last@ment.gov.au,SecretPassword!1
#dave.colv.in,SecretPassword!1
#Write-Output "Startup "
Import-Csv ".\ChurnReset.csv" | Foreach {
$email = $_.email
$dynamicPW = $_.password #use this the passwords in the CSV
$setPW = "davecolvin00111!!" #use this for a preset password
#Write-Output "checking user -> $email password -> $dynamicPW"
try {
#Get-ADUser $user
$user = Get-ADUser -Filter {mail -like $email } -SearchBase "DC=dec,DC=int" -searchscope subtree -Properties samAccountName
Set-ADAccountPassword $user -NewPassword (ConvertTo-SecureString $setPW -AsPlainText -force) -Reset
Enable-ADAccount $user
Write-Output "$user, Password reset and enabled"
} catch
{ Write-Output "$user,Error" }
} # <-remove if you want a log file instead of screen | Out-File PassChange.log