We are cleaning up AD and it’s a bear to do manually. What I have:<\/p>\n
ProjectXYZ (Role Group)<\/p>\n
What I want:<\/p>\n
Basically, the idea is to extract the users from the nested AD Group, store it, add them back into ProjectXYZ role group. When completed, delete the nested Role Group, close the project and go drink something strong.<\/p>","upvoteCount":8,"answerCount":10,"datePublished":"2016-09-08T17:27:25.000Z","author":{"@type":"Person","name":"gcarter","url":"https://community.spiceworks.com/u/gcarter"},"acceptedAnswer":{"@type":"Answer","text":"
This should get you started. Specify the name of the group that you want to clean up on line 1. It will roll through the members of that group looking for any that are also groups. Then it moves the “sub-group” members up one level and deletes the sub-group.<\/p>\n
$TargetGroup = 'Users.RealPresence'\nForEach ($Member in Get-ADGroupMember -Identity $TargetGroup) {\n if ($Member.objectclass -eq 'group') {\n write-host $Member.name\n ForEach ($SubMember in Get-ADGroupMember -Identity $Member.Name) {\n Add-ADGroupMember -Identity $Member.name -Members $SubMember.SamAccountName -whatif\n write-host $SubMember.name\n }\n Remove-ADGroupMember -Identity $TargetGroup -Members $Member -whatif\n Remove-ADGroup -Identity $Member -whatif\n }\n}\n\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2016-09-08T18:24:07.000Z","url":"https://community.spiceworks.com/t/ad-powershell-replace-nested-groups-with-members-of-said-group/524271/7","author":{"@type":"Person","name":"glenn-p","url":"https://community.spiceworks.com/u/glenn-p"}},"suggestedAnswer":[{"@type":"Answer","text":"We are cleaning up AD and it’s a bear to do manually. What I have:<\/p>\n
\n- \n
ProjectXYZ (Role Group)<\/p>\n
\n- Members:\n
\n- DepartmentJ (Role Group)<\/li>\n
- User 1<\/li>\n
- User 2<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
What I want:<\/p>\n
\n- ProjectXYZ (Role Group)<\/li>\n
- Members:<\/li>\n
- User 1<\/li>\n
- User 2<\/li>\n
- User 3<\/li>\n
- User 4<\/li>\n
- User 5<\/li>\n<\/ul>\n
Basically, the idea is to extract the users from the nested AD Group, store it, add them back into ProjectXYZ role group. When completed, delete the nested Role Group, close the project and go drink something strong.<\/p>","upvoteCount":8,"datePublished":"2016-09-08T17:27:25.000Z","url":"https://community.spiceworks.com/t/ad-powershell-replace-nested-groups-with-members-of-said-group/524271/1","author":{"@type":"Person","name":"gcarter","url":"https://community.spiceworks.com/u/gcarter"}},{"@type":"Answer","text":"
I assume that you are willing to specify the parent group rather than have this thing wading through your entire AD structure making mass changes throughout. Correct?<\/p>","upvoteCount":1,"datePublished":"2016-09-08T17:43:35.000Z","url":"https://community.spiceworks.com/t/ad-powershell-replace-nested-groups-with-members-of-said-group/524271/2","author":{"@type":"Person","name":"glenn-p","url":"https://community.spiceworks.com/u/glenn-p"}},{"@type":"Answer","text":"
have you looked into Role Based Access Control (RBAC), rather than per user per project?<\/p>","upvoteCount":0,"datePublished":"2016-09-08T17:44:38.000Z","url":"https://community.spiceworks.com/t/ad-powershell-replace-nested-groups-with-members-of-said-group/524271/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Also, do your nesting levels go more than 2 deep? (Groups within groups within groups…)<\/p>","upvoteCount":0,"datePublished":"2016-09-08T17:51:35.000Z","url":"https://community.spiceworks.com/t/ad-powershell-replace-nested-groups-with-members-of-said-group/524271/4","author":{"@type":"Person","name":"glenn-p","url":"https://community.spiceworks.com/u/glenn-p"}},{"@type":"Answer","text":"