# Combine output from Get-ADGroupmember and Get-ADGroup from .csv file

**URL:** <https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183>\
**Category:** PowerShell Help\
**Created:** [March 12, 2019, 4:52pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183 "2019-03-12T16:52:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 12, 2019, 4:52pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/1 "2019-03-12T16:52:08Z")

</div>

Good afternoon experts!

I’m trying to get the following information from get-adgroupmember and get-adgroup groupname, groupdescription, groupinfo and groupmembers using the following script

$GNames = Import-CSV -Path D:\Powershell\_temp\danea\_info.csv| ForEach-Object {  
Get-ADGroup -Filter “Name -like ‘_$($\_.name)_’” -Properties \* } | Select-Object Name

$results = foreach ($GName in $GNames) {  
Get-ADGroupMember -ID $GName | select samaccountname, name, @{n=‘GroupName’;e={$GName}}, @{n=‘Description’;e={(Get-ADGroup $GName -Properties description).description}}  
}

$results

Here is the error(s) I’m seeing:  
Get-ADGroupMember : Cannot bind parameter ‘Identity’. Cannot create object of type “Microsoft.ActiveDirectory.Management.ADGroup”. The adapter cannot set the value of property “Name”.

## Here is a snip from $GNames Name

apabcd\_Server\_Test\_Group  
ClientVirusQuarantine  
dgabcd3

Any and all input would be greatly appreciated

Norm

---

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 12, 2019, 5:39pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/2 "2019-03-12T17:39:23Z")

</div>

Got it to work sort of…  
The following script works, but it only displays the ADGROUPS that contain members. My goal would be to list all groups contained in $GNames that is to say include the ADGROUPS with no group members.

$GNames = Import-CSV -Path D:\Powershell\_temp\danea\_info.csv| ForEach-Object {  
Get-ADGroup -Filter “Name -like ‘_$($\_.name)_’” -Properties \* }

$results = foreach ($GName in $GNames) {  
Get-ADGroupMember -ID $GName | select name, @{n=‘GroupName’;e={$GName}}, @{n=‘Description’;e={(Get-ADGroup $GName -Properties description).description}}  
}

$results

---

<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:** [March 12, 2019, 6:12pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/3 "2019-03-12T18:12:54Z")

</div>

Please format your code as code using the code tag button right above the edit windows of the post editor. Thanks.

I think you’d be better off using PSCustomObjects like this:

```
$GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv |
ForEach-Object {
Get-ADGroup -Filter “Name -like ‘_$($\_.name)_’” -Properties *
}

$results = foreach ($GName in $GNames) {  
$Members = Get-ADGroupMember -ID $GName  
[PSCustomObject]@{  
GroupName = $GName.Name  
Description = $GName.Description  
Members = $Members.Name  
}  
}

$results
```
… unteted, but should work actually … 😉

---

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 13, 2019, 11:00am UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/4 "2019-03-13T11:00:57Z")

</div>

Hello Olaf;  
Thank you for your suggestion it gets me a whole lot closer to what I’m looking for! On problem remains when there is more than one member I’m getting the following display in the Members column:

System.Object

Here is actual output in $results for the row displaying System.Object:  
{jsmith, jdoe}

Any thoughts as to why this is occurring?

Norm

---

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 13, 2019, 11:30am UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/5 "2019-03-13T11:30:13Z")

</div>

Hi Olaf;  
So the following script

```
$GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv| ForEach-Object { 
    Get-ADGroup -Filter "Name -like '*$($_.name)*'" } 
$results = foreach ($GName in $GNames) {
    Get-ADGroupMember -ID $GName | select name, @{n='GroupName';e={(Get-ADGroup $GName -Properties Name).Name}}, @{n='Description';e={(Get-ADGroup $GName -Properties description).description}}, @{n='Info';e={(Get-ADGroup $GName -Properties info).info}}
}

$results
```

Produces the following output  
name GroupName Description Info

* * *

park dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
kim dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
chs dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
aroney dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
ngelpo dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
davis dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
amagna dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
krivan dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
arr dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
ivilla dgVPN-XXSVDI Two factor VPN - Access to XXS VDI  
row BudgetCopyRO  
clure BudgetCopyRO

As you can see there are two ADGroups containing multiple members, again your suggestion gets me very close to what I’m looking for, only issue is the output of group members.

Thanks again for your input  
Norm

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [March 13, 2019, 11:40am UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/6 "2019-03-13T11:40:24Z")

</div>

Try wrapping them in quotes,

Members = “$($Members.Name)”

---

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 13, 2019, 12:15pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/7 "2019-03-13T12:15:05Z")

</div>

Hello kvprasoon,  
Well that worked thank you!! Now the next question is why, don’t understand why your suggestion worked. If you don’t have the time to explain that’s okay.

Thanks again  
Norm

By the way how do I assign points?

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [March 13, 2019, 1:02pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/8 "2019-03-13T13:02:59Z")

</div>

As for this…

```
"$($Members.Name)"
```

… this is a way of expanding the content of the variable contents and / or grouped stings. This is a very common thing done in PS.

See this write-Up

> Powershell String Expansion http://www.powershellish.com/blog/2014-12-09-strings-expansion
> 
> > **[Variable expansion in strings and here-strings - PowerShell Team](https://devblogs.microsoft.com/powershell/variable-expansion-in-strings-and-here-strings/)**
> >
> > PSMDTAG:FAQ: What is the difference between single quoted and double quoted strings?  ANSWER:  Double quoted string expand variables and single quoted strings do not. Example: PS\> $x=”TEST”PS\> “This is a $x”This is a TESTPS\> ‘This...

As for this…

> By the way how do I assign points?

… you don’t. It’s done by an underlying process of the site.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [March 13, 2019, 1:36pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/9 "2019-03-13T13:36:42Z")

</div>

Thanks @postanote for the explanation.

@nlong12 I was doing a quick round up through the posts, hence missed to explain it.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [March 14, 2019, 3:25pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/10 "2019-03-14T15:25:21Z")

</div>

no worries

---

<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:33pm UTC](https://forums.powershell.org/t/combine-output-from-get-adgroupmember-and-get-adgroup-from-csv-file/12183/11 "2024-05-16T20:33:08Z")

</div>


