Hi
I am trying to create a script that will compare our AD against a CSV file exported from our CMS system so that we can ensure that both have the same information. We need this report to contain only users that are not found in AD and then email the results.
We will then check the email and determine which is incorrect AD or CMS.
I have created the below script and it checks AD against the CSV but emails me all the results, can someone please assist me with filtering this to only the users that are not found?
#Snap-ins needed to use the commands within the script
if((Get-pssnapin-NameMicrosoft.Exchange.Management.Powershell.E2010-ErrorActionSilentlyContinue) -eq$null){Add-PSSnapinMicrosoft.Exchange.Management.PowerShell.E2010}
if((Get-pssnapin-NameQuest.activeroles.admanagement-ErrorActionSilentlyContinue)-eq$null){Add-pssnapinQuest.activeroles.admanagement}
$Results = @()
ForEach ($Userin (Import-Csvc:\scripts\users.csv))
{ If (Get-QADUser$User.Name)
{ $Status="Found"
}
Else
{ $Status="Not Found"
}
$Results +=New-ObjectPSObject-Property @{
Username =$User.Name
Status =$Status
}
}
$Results |SelectUsername,Status|Export-Csvc:\Scripts\validatedusers.csv -NoTypeInformation
Send-MailMessage -Fromemail@domain.com-Toemail@domain.com-Subject"AD Compare"-Attachments"C:\scripts\validatedusers.csv"-SmtpServer Server
The CSV file has the following headers and information
ID,Forename,Surname,Name
112,John,Smith,John Smith
Any assistance would be appreciated, I am at the end of my limited knowledge.
Thanks