Getting / Separating Group Owners RRS feed

  • General discussion

  • Hi there, after many hours of scouring here and elsewhere on the Interwebs, I'm very stuck and wouldn't be posting if I could find a way on my own.  Here's the issue:

    1. Find all groups where a specific user is an owner (done)

    2. From those groups, list only owners who are not admin (admin accounts are in the format of "username_a" and my team's admin accounts are 'owners' of all DG's and SG's

    3. After extracting only the end users who are owners, re-apply the 'managedby' permissions with those end users from step 2, and a new security group.

    For step one, I'm using:

    Get-DistributionGroup * | Where-Object {$_.managedby -like "*lemmen*"} | select name,managedby -first 10

    A) This successfully gives me a list of the DL name, and the complete list of 'managedby', as intended.

    B) The user 'lemmen' was one of our admins, but no longer, hence wanting to identify groups where that name is still attached as an owner.

    My question is:  How do i do steps 2 and 3 above?  I need to extract the end user owners' Usernames (samaccountname), so getting just their usernames is the first challenge, and then how do I take THOSE results and re-apply them to the original list of groups from step 1?

    I've even tried exporting the list of group names from #1 to a .csv, then reading from that and running this:

    % {Get-DistributionGroup $_.name | select name,managedby}


    % {Get-DistributionGroup $_.name | select name -expandproperty managedby}

    but all that does is give me a list of the owners in formats I don't want

    PS: I'm not interested in the Get-ADGroup and the single ManagedBy field results, thanks

    Any help would be very much appreciated, thank you!

    • Changed type Bill_Stewart Friday, March 15, 2019 5:23 PM
    • Moved by Bill_Stewart Friday, March 15, 2019 5:24 PM This is not "train me in basics step-by-step in a forum" forum
    Wednesday, January 9, 2019 8:47 PM

All replies