I have a .csv file with the column names "Display Name, Email Address and SameAccountName". I want to compare this .csv file to active directory. So essentially, if any emails under "EmailAddress" from the .csv file does not match the "EmailAddress" from AD, I want to export the names that does not match into a separate .csv file named "inactiveusers.csv".
My script :
$csv=Import-Csv -Path C:\Users\renu\Desktop\renu\ALLUserMain30082021.csv
$ad = Get-ADUser -Filter "Enabled -eq 'True'" -SearchBase 'OU=example,DC=example,DC=example,DC=example'
Compare-Object -ReferenceObject $csv.EmailAddress -DifferenceObject $ad.EmailAddress -IncludeEqual -ExcludeDifferent | Select-Object -Property InputObject | Export-Csv -Path C:\Users\renu\Desktop\renu\match.csv -NoTypeInformation
Compare-Object -ReferenceObject $csv.EmailAddress -DifferenceObject $ad.EmailAddress | Select-Object -Property InputObject | Export-Csv -Path C:\Users\renu\Desktop\renu\notmatchusers.csv -NoTypeInformation
When i run the code i get the following error message.