0

I'm trying to expand Members property in powershell whithout success :(

Here is my code...

Import-Module ActiveDirectory
Get-ADGroup -Filter * -Properties * | 
   Select-Object -Property Name, Description, GroupCategory,`
  @{Name='Members';exp={Get-adgroupmember $_.Name | Select -Expand Name |Select}} |
   format-list -Property Name,  Members, Description, GroupCategory

Members property that I want to expand

0

2 Answers 2

1

If all you need is a list of the group members:

Get-ADGroupMember "Remote Desktop Users" -Recursive | Select samaccountname

gives you a list of accounts names, OR

Get-ADGroupMember "Remote Desktop Users" -Recursive | Select name

gives you a list of the user's name (as entered into AD)

Save yourself some time and finish by piping output to a file with something like:

abovecommand | Out-File "C:\Users\username\Desktop\RDU_members.txt" -Append

If you still want to pull the full description of the group itself, you could use:

Get-ADGroup -Filter {name -like "Remote Desktop Users"} 

OR you could simply remove the select from one of the first two statements to keep the same format of output (one block per account).

Salt and pepper to taste. Hope this helps.

0

You can do someting like that:

Import-Module ActiveDirectory   

Get-ADGroup -Filter * -Properties * | ForEach-Object {
        $MyGroup= New-Object PSObject
        Add-Member -InputObject $MyGroup -MemberType NoteProperty -Name "Name" -Value $_.Name
        Add-Member -InputObject $MyGroup -MemberType NoteProperty -Name "Category" -Value $_.GroupCategory
        $Members= Get-ADGroupMember $_.Name | Select-Object -ExpandProperty Name
        $Members= $Members -join "`r`n"
        Add-Member -InputObject $MyGroup -MemberType NoteProperty -Name "Members" -Value $Members
        Write-Output $MyGroup | Format-List
    }

Possibly you can improve it as you need.

3
  • Thanks for your answer, I tried something like this. But didn't work :( code $Members= Get-ADGroupMember $_.Name | Select-Object -ExpandProperty Name code This property is still appearing with " ..." after five members. I would like to show all members. When I select only Name and expand property, It works fine. But It dont show Group name and Description, only group members in a loooong list. Jul 5, 2017 at 17:38
  • @DiegoAlvesdeLima So you need to concatenate all group members to one string. I edited code above, so check out if it suits you.
    – mrc02_kr
    Jul 5, 2017 at 18:13
  • 1
    Set var $formatenumerationlimit = -1 to end the truncation.
    – blaughw
    Jul 5, 2017 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .