I have a list of email addresses in a CSV file from which I would like to get the employee number against each row exported into a new CSV file. I tried with a powershell script but am struggling a bit and was wondering if somebody could point me in the right direction.
Import-Module ActiveDirectory
Import-Csv 'C:\ps\EmailIDIFS.csv' | ForEach {
Get-ADUser -Filter "EmailAddress -eq '$($_email)'" -Properties Name,
emailAddress, SAMAccountName, employeeNumber | `
Select Name, emailAddress, SamAccountName, employeeNumber | `
Export-CSV 'C:\ps\ADResults.csv' -NoTypeInformation
}
Unfortunately when I run this I get the following error:
Get-ADUser : The search filter cannot be recognized At C:\Users\jfoote\Nextcloud\Local\scripts\ADEmployeeNumber.ps1:3 char:1 + Get-ADUser -Filter "EmailAddress -eq '$($_email)'" -Properties Name, ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser