Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (40 sloc) 1.41 KB
function Move-ADGroupMemberofToMember {
Moves all Member Of objects to the Members section of an Active Directory group.
Queries an Active Directory group for all Member Of groups then add them to the members section
and removes them from the member of section of the active directory group.
.PARAMETER TargetGroup
Specify the group to run the cmdlet against.
Move-ADGroupMemberOfToMember -TargetGroup GroupTest01 -Verbose
Write-Verbose -message "Gathering all Member of objects"
$Groups = (Get-ADGroup -Identity $TargetGroup -Properties *).Memberof
foreach ($Group in $Groups) {
Try {
Write-Verbose -message "Adding $Group as member"
Add-ADGroupMember -Identity $TargetGroup -Members $Group
Write-Verbose -message "Removing $Group from Member of"
Remove-ADGroupMember -Identity $Group -Members $TargetGroup -Confirm:$false
Catch [Microsoft.ActiveDirectory.Management.ADException] {
Write-Warning -message "$Group was already a member of $TargetGroup"
Write-Verbose -message "Removing $Group from Member of"
Remove-ADGroupMember -Identity $Group -Members $TargetGroup -Confirm:$false
Write-Verbose -message "Migration of Member of to Member complete"