Script to convert users display name to sam id

rov17
rov17 used Ask the Experts™
on
Hi everyone,

I need a power shell, vbs script to check an excel sheet or even a csv file that has a display name for some users and convert them to SAMID and output the results in a text file.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chris DentPowerShell Developer
Top Expert 2010

Commented:

If you were to go with PowerShell, and had Quest's CmdLets there's not much more to it than this:


Import-CSV "YourCSVFile.csv" | `
  %{ Get-QADUser $_.Name } | `
  Select Name, sAMAccountName | `
  Export-CSV "SomeNewFile.csv"


That assumes the CSV file has a column called Name. If it encounters a duplicate name in AD it will output all matches.

Chris

Author

Commented:
Hi Chris,

Thank for the script, actually the csv file as First name , last name.
Is there is away to get the script checks both First name and the last name ?

Thanks
PowerShell Developer
Top Expert 2010
Commented:

Yep. Assuming columns called FirstName and LastName (with no spaces) it can be this.

If there are spaces in the column name it would be $_."First Name", etc.

Chris
Import-CSV "YourCSVFile.csv" | `
  %{ Get-QADUser -FirstName $_.FirstName -LastName $_.LastName } | `
  Select Name, sAMAccountName | `
  Export-CSV "SomeNewFile.csv"

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial