February 12, 2014

PowerShell - Active Directory query

How to query AD using list of users in format - "Surname, First Name"?

test.csv file format:
Identity
"Surname1, FirstName 1"
"Surname2, FirstName 2"
"Surname3, FirstName 3"
"Surname4, FirstName 4"
"Surname5, FirstName 5"

PowerShell script:
Import-Csv test.csv | foreach { $U = $_.Identity; Get-AdUser -filter { DisplayName -eq $U }}

No comments:

Post a Comment