locked
Powershell- output groupname,managedby and members RRS feed

  • Question

  • Hi,

    I know that there is a lot of group member questions. But I cant seem to find the exact answer I'm looking for.

    I want to search part of the AD and get all the groups with their owner (managedby) as well as the members.

    This will be exported into a CSV with three columns groupname,member,managedby.

    So far I have been able to get the groupname and members but not the Managedby

    Any help would be great! 

    Below is where I am at so far.

    Get-ADGroup -Filter * -searchbase "OU=,OU=,OU=,OU=,OU=,DC=,DC=" |
         ForEach-Object{
    $hash=@{GroupName=$_.Name;Member=''}
              $_ | Get-ADGroupMember -ea 0 -recurs |
                   ForEach-Object{
                        $hash.Member=$_.Name
                        New-Object psObject -Property $hash
                   }
              } | 
              sort groupname,member |
              export-CSV -path C:\Powershell_results\adgroupmembers.csv

             
    Wednesday, June 7, 2017 2:49 PM

Answers

  • Get-ADGroup -Properties ManagedBy
    ManagedBy is not a default property so you must request it

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • Proposed as answer by Richard MuellerMVP Wednesday, June 7, 2017 3:16 PM
    • Marked as answer by Yorkie89 Wednesday, June 7, 2017 3:19 PM
    Wednesday, June 7, 2017 2:52 PM

All replies

  • Get-ADGroup -Properties ManagedBy
    ManagedBy is not a default property so you must request it

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • Proposed as answer by Richard MuellerMVP Wednesday, June 7, 2017 3:16 PM
    • Marked as answer by Yorkie89 Wednesday, June 7, 2017 3:19 PM
    Wednesday, June 7, 2017 2:52 PM
  • Ah yes, thanks

    Do you know how to export that so that it can be selected for every group?

    Wednesday, June 7, 2017 3:06 PM
  • Just add the -Properties parameter to your Get-ADGroup command, then retrieve managedBy the same way you retrieve the group Name. The value is a single valued string (similar to the Name), but is the distinguishedName of the manager of the group.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Wednesday, June 7, 2017 3:18 PM