It gets the information I request, but I get an ugly error message for every email address
Anyone who know whats wrong so I can remove that error message.
#Location
$txt_location = "Emaillist.txt"
$csv_location = "Emaillist-test.csv"
#Fetch from AD
Get-Content $txt_location | forEach {Get-ADUser -Filter {EmailAddress -eq $_ } -Properties msRTCSIP-PrimaryUserAddress, EmailAddress, Manager | Select-Object msRTCSIP-PrimaryUserAddress, EmailAddress,
@{name='ManagerFirstname';expression={(Get-ADUser -Identity $_.manager | Select-Object -ExpandProperty Givenname)}},
@{name='ManagerLastName';expression={(Get-ADUser -Identity $_.manager | Select-Object -ExpandProperty Surname)}},
@{name='ManagerUserID';expression={(Get-ADUser -Identity $_.manager | Select-Object -ExpandProperty SamAccountName)}},
@{name='ManagerEmailAddress';expression={(Get-ADUser -Identity $_.manager -Properties emailaddress | Select-Object -ExpandProperty emailaddress)}}} | Format-Table -AutoSize | Out-File $csv_location
Error message:
Get-ADUser : The search filter cannot be recognized
At C:\Test\Get-User_byEmail-tes1.ps1:16 char:52
+ ... | forEach {Get-ADUser -Filter {EmailAddress -eq $_ } -Properties msR ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser