01 January,2018 by Tom Collins
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:
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |