none
Circular Nested groups RRS feed

  • Question

  • Good day,

    I am working on circular nested groups, where a group is a member of itself. A script was created to find these groups. I created 3 Test groups as a test.

    The script generates a *.csv file and the output displays 2 column headers, Group Name and then Member groups.

    I now want to import this *.csv file with the column headers, and then based on this, go to each group and then remove the membership from itself. How would I
    change the script to do this?
    • Moved by Bill_Stewart Wednesday, September 4, 2019 7:46 PM This is not "fix/debug/rewrite script for me" forum
    Monday, April 1, 2019 7:10 AM

All replies

  • Script used:

    $Report = @()
    $GroupCollection = Get-ADGroup -Filter {name -like "*TestGroup*"} | select Name,MemberOf,ObjectClass,SAMAccountName

    Foreach($Group in $GroupCollection){
    $MemberGroup = Get-ADGroupMember -Identity $Group.SAMAccountName | where{$_.ObjectClass -eq ‘group’}
    $MemberGroups = ($MemberGroup.Name) -join “`r`n”
    if($MemberGroups -ne “”){
    $Out = New-Object PSObject
    $Out | Add-Member -MemberType noteproperty -Name ‘Group Name’ -Value $Group.Name
    $Out | Add-Member -MemberType noteproperty -Name ‘Member Groups’ -Value $MemberGroups

        $Report += $Out
    }
    }
    $Report | Sort-Object Name | FT -AutoSize
    $Report | Sort-Object Name | Export-Csv -Path ‘C:\Temp\TestGroup_Report.csv’ -NoTypeInformation

    Monday, April 1, 2019 7:11 AM
  • The output

    "GroupName","MemberGroups"
    "TestGroup 3","TestGroup 1
    TestGroup 2"
    "TestGroup 2","TestGroup 1
    TestGroup 3"
    "TestGroup 1","TestGroup 2
    TestGroup 3"

    Monday, April 1, 2019 7:13 AM
  • Help import-csv -online

    help remove-adgroupmember -online


    \_(ツ)_/

    Monday, April 1, 2019 7:20 AM