Hi, this is a long list of values(Employee ID) in csv file to be deleted from AD. The employee ID is stored in extensionattribute15 in AD.
The function of the script is to search for AD users where extensionattribute15(store Employee ID) is identical to the values in CSV file. There is only 1 column in the csv file. The script below is not working, can you assist? Any help
would be greatly appreciated. Thanks.
Script start here:
Import-Module ActiveDirectory
$users = Import-Csv -Path C:\test\Test.csv
$today = get-date
foreach ($user in $users) {
$UserChkExist = Get-ADUser -Filter "extensionattribute15 -eq '$($user.EmployeeID)'"
$today = get-date
If ($UserChkExist -eq $null)
{
Add-Content C:\Test\TestFAIL.log "$($user.EmployeeID) not amended on $Today"
}
else{
Get-ADUser -Filter "extensionattribute15 -eq '$($user.EmployeeID)'"|Remove-ADUser
Add-Content C:\Test\Test.log "$($user.EmployeeID) amended on $Today"
}
}