Wednesday, September 30, 2015

Script to read in email addresses and set passwords, enable accounts

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:




#Write-Output "Startup "

Import-Csv ".\ChurnReset.csv" | Foreach {

$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

Post a Comment

Blog Archive