Friday, September 12, 2014

PowerShell: One liner get distinguishedname for all user accounts in text file

One liner to get users from a text file and create a report of distinguishedname. You need the activedirectory module imported to run.

import-module activedirectory

gc "C:\temp\serviceaccounts.txt" | Foreach-Object {Get-ADUser -filter {CN -like $_} -Properties *} | select Name, SAMAccountName, distinguishedname | export-csv -path c:\temp\test.csv

No comments:

Post a Comment

Powershell: AD DHCP scope information