# Get-ADGroup \<groupname -Properties Members

**URL:** <https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100>\
**Category:** PowerShell Help\
**Created:** [April 11, 2023, 1:56pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100 "2023-04-11T13:56:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasHGW](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@AndreasHGW](https://forums.powershell.org/u/AndreasHGW)\
**Post date:** [April 11, 2023, 1:56pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/1 "2023-04-11T13:56:55Z")

</div>

Hello  
we have a lot of AD groups which have members from 2 different domains within our forest.  
To get the member of a group I usually would use the command

```auto
Get-ADGroupMember

```

But if a group contains members from different domains you can not use this command, because you get a exeption error.

That’s why I deceided to use the command

```auto
Get-ADGroup <groupname> -Properties Members | select members

```

But using the command the output is not only the members of the group, but together with the OU, like

```auto
{CN=ynl,OU=Benutzer,OU=Users,DC=ixx,DC=max,DC=de, CN=suupo,OU=Benutzer,OU=Users....

```

How can I filter the output, that I just get the names of the members ( get only the CN)

thanks  
Andreas

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 11, 2023, 2:10pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/2 "2023-04-11T14:10:03Z")

</div>

> [@AndreasHGW](#):
>
> the output is not only the members of the group, but together with the OU

Actually it is the Distinguished Name you get. If you want to get the Common Name (CN) you may query the according AD for this attribute or you use string acrobatics. 😉

Given your example output it could look like this:

```auto
$DN = 'CN=ynl,OU=Benutzer,OU=Users,DC=ixx,DC=max,DC=de'
(($DN -split ',OU')[0] -split '=')[1]

```

---

<div class="post-metadata">

**Author:** ![AndreasHGW](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@AndreasHGW](https://forums.powershell.org/u/AndreasHGW)\
**Post date:** [April 11, 2023, 2:31pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/3 "2023-04-11T14:31:26Z")

</div>

> [@Olaf](#):
>
> `(($DN -split ',OU')[0] -split '=')[1]`

I do not want the Distinguished Name itself as the result, but I want all members within the group.  
Means the output in my excample should be

```auto
ynl,suupo

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 11, 2023, 2:33pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/4 "2023-04-11T14:33:33Z")

</div>

> [@AndreasHGW](#):
>
> I do not want the Distinguished Name itself as the result, but I want all members within the group.

I know. You have to do this step for each individual member of a group … so you have to use a loop. 😉

---

<div class="post-metadata">

**Author:** ![AndreasHGW](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@AndreasHGW](https://forums.powershell.org/u/AndreasHGW)\
**Post date:** [April 11, 2023, 2:43pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/5 "2023-04-11T14:43:55Z")

</div>

OK, but how I get the CNs from that $DN string?

If I run your commands, I get as result the name of the group itself , OU.  
In the output there is none of the members included.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 11, 2023, 2:55pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/6 "2023-04-11T14:55:25Z")

</div>

```auto
$MemberList = 
    Get-ADGroup '<groupname>' -Properties Members | 
        Select-Object -ExpandProperty members
foreach ($Member in $MemberList) {
    (($Member -split ',OU')[0] -split '=')[1]
}  

```

---

<div class="post-metadata">

**Author:** ![AndreasHGW](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@AndreasHGW](https://forums.powershell.org/u/AndreasHGW)\
**Post date:** [April 11, 2023, 2:59pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/7 "2023-04-11T14:59:36Z")

</div>

Thank you, that works fine… 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/get-adgroup-groupname-properties-members/22100/8 "2024-05-16T20:14:56Z")

</div>

Closed on May 16, 2024, 8:14pm UTC


