Reading a CSV using Powershell Script

I am trying to get my script to do the following things:

- read a CSV script

- compare what is in the CSV script to AD

- Determine which of the accounts in the CSV are active in AD

- Put those results into a CSV in a designated folder

- Notify me when done via email (I know how to do this).

This is what I have:

Import-Csv -Path [path to csv]" |
Foreach-Object  { $PSItem | Get-Member } |
Get-ADUser -Filter * -Searchbase "DC=xxx,DC=xxx" -Properties ipPhone,EmailAddress |
Where-Object {$_.Enabled -eq $true} | 
Select-Object SAMAccountName,ipPhone,EmailAddress |
Export-Csv -Path [export location] -NoTypeInformation

Any assistance is really appreciated. I've removed sensitive information due to confidentiality reasons.

Also, it works to print out all the enabled users in AD, but it is not comparing the imported CSV. I think the error is in the foreach-object line, but I cannot figure out how to fix it.

Parents Reply Children