How to get DOMAIN login name with Powershell Get-ADGroupMember

01 January,2018 by Jack Vamvas

Question: I’ve read the article How to Export Active Directory Group Members with Powershell Get-ADGroupMember . This article  has a script to export the members of the AD group , but it exports the name. I require the DOMAIN_NAME\login_name  information .

Select name – returns the name , which columns do I return which would give me the DOMAIN_NAME\login_name ?

Answer: The Get-ADGroupMember cmdlet is very efficient at returning AD group members , but it does require some manipulation to get back the DOMAIN_NAME\login_name combination. I’m assuming you’ve installed the Powershell Active Directory module for Windows. If you haven’t then the first step is to install the AD module for Windows , use these instructions: How to install the Active Directory Module for Windows

You’ll notice the first part of the powershell  script  is similar to obtaining a list of names in the selected Active Directory Group. The difference is to pipe the resultset , extract the DistinguishedName , SameAccountName and then do some string manipulation using the powershell spilt and replace functions.

 

Get-ADGroupMember -identity 'INSERT_MY_GROUP-NAME' –Recursive  | select-object @{name="Login";expression={(($_.DistinguishedName  -split '(DC=)')[2] -replace ',')+"\"+$_.SamAccountName}}

For further reading on Powershell scripting read:

Powershell Scripts

 

 

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to get DOMAIN login name with Powershell Get-ADGroupMember


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer