Got the CSV in below Format –
EmployeeID | Username | EndDate |
EES01 | Ram.shankar | 4/6/2016 |
EES02 | Ajay.george | 11/28/2016 |
EES03 | Karthick.Kane | 5/25/2016 |
EES04 | Vaishika.Sathesh | 9/1/2016 |
- Always change the format to MM/DD/YYYY – Please verify in your case. (Note : TO change formats in bulk excel is the best choice Choose those columns – Format Cells and choose the type you want)
- Accounts get expired in a day prior which you specify here.
Like Query for an Existing user who as an existing expiry date . And verify the format.
Get-ADUser -Identity sathesh.manoharan -Properties accountexpirationdate
Login to an Domain Controller
Open PowerShell – Run as Administrator
Import-Module ActiveDirectory
TO Check Prior (WHATIF) – (Note: Shell is pointing to CSV location or change the CSV location like C:\ )
Import-Csv '.\Employees.csv' | foreach {Set-ADAccountExpiration -identity $_.username -Date Time $_.EndDate -whatif}
TO Change –
Import-Csv '.\Employees.csv' | foreach {Set-ADAccountExpiration -identity $_.username -Date Time $_.EndDate}
Perfect, thanks for posting!