Mahmoud ElMansy: knowledge meant to be free

PowerShell Search For list Of Users

Power-Shell Is a very handy tool for administrators.
We meet again with this post to demonstrates hoe to get users info from active directory for list of users stored in CSV File

First we will make Text File with Search Criteria separated by comma


Save it in CSV File New.csv

Now to PowerShell Code
[cc lang=”c#”]
Import-Module ActiveDirectory

$FilePath =’.\New.csv’
$Users = Import-Csv $FilePath -Header(’email’) -Delimiter ‘,’

foreach($user in $Users)
$email=[string]::Format(“{0}*”, $user.comment);
Get-ADUser -Filter {(Comment -like $email)} -Properties *| select mail,name,cn | Export-Csv -Path ‘\Out.csv’ -NoTypeInformation -Append
#Write-Host $email