PowerShell for Windows Admins

Jan 26 2015   12:41PM GMT

Unravelling lists of distinguished names

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Active Directory

There are a number of AD properties such as MemberOf and directrports that consist of a collection of distinguisednames. Sometimes you need the name of the object rather than the distinguished name:

function getname {
param (

$name = Get-ADObject $dn | select -ExpandProperty Name

return $name
Get-ADUser -Filter * -SearchBase “OU=Testing,DC=Manticore,DC=org” -Properties MemberOf |
foreach {

$name = $psitem.Name

foreach ($member in $psitem.MemberOf) {
$props = [ordered]@{
User = $name
Group = getname -dn $member

New-Object -Property $props -TypeName PSObject


In this example I’m looking at the MemberOf property. Pull back the set of users and foreach look at each member in the MemberOf list. I pass that to a function that returns the name – I can reuse the function in other scripts.

Don’t make the mistake of looking at group membership in this way though. You can get the names of group members much more simply

Get-ADGroupMember -Identity tg1 | select name

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: