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

email,
email1@contoso.com,
email2@contoso.com,
email3@contoso.com,
email4@contoso.com,
email5@contoso.com,

Save it in CSV File New.csv

Now to PowerShell Code

Import-Module ActiveDirectory

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

foreach($user in $Users)
{
 #$email='"'+$user.comment+'*"'
 $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
}