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

Comments

Popular posts from this blog

Powershell - Com+ Application Recycle

Powershell : Certutil Find Expired Certs on CA server