Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Compare CSV to AD to find missing details

$
0
0

Hi

I am trying to compare all users within a specific OU against a CSV file to check that AD has all the correct information and no spelling mistakes.

The CVS headings are sn, givenName, employeeID and contains 100+ users

I can get the following to work when I only have a single name in the CSV but when I add additional names it doesnt work. The script needs to check the AD user's sn, givenName and employeeID and if any of these fields are different from the CSV it needs to email the name and field that is incorrect to our ICT support email.

At the moment I have only tried to get it to export to a CSV but cannot get that working. Any help please much appreciated.

My script as far as I have got:-

$ID = Import-Csv -Path "c:\scripts\csv\staffchanges.csv" | Select-object -ExpandProperty EmployeeID
$FirstName = Import-Csv -Path "c:\scripts\csv\staffchanges.csv" | Select-object -ExpandProperty givenName
$Surname = Import-Csv -Path "c:\scripts\csv\staffchanges.csv" | Select-object -ExpandProperty sn
$CSVADMismatch = "C:\scripts\output.csv"

Get-ADUser -filter * -SearchBase "OU=Staff,OU=Users,DC=domain,DC=com" -Properties * |

       ForEach-Object { Where-Object{$_.givenName -ne $FirstName -or $_.sn -ne $Surname -or $_.EmployeeID -ne $ID} | Select-Object name, givenName, sn, employeeid | Export-Csv -NoTypeInformation -path $CSVADMismatch}

Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles