Last active
November 8, 2015 03:15
-
-
Save duffney/650e6fd2f16710621cb0 to your computer and use it in GitHub Desktop.
Single Domain support Move-ADGroupMemberofToMember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Move-ADGroupMemberofToMember { | |
<# | |
.SYNOPSIS | |
Moves all Member Of Groups to the Members section of an Active Directory group. | |
.DESCRIPTION | |
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 Identity | |
Specify the group to run the cmdlet against. | |
.EXAMPLE | |
Move-ADGroupMemberOfToMember -Identity GroupTest01 -Verbose | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$True)] | |
[string]$Identity | |
) | |
BEGIN { | |
Write-Verbose -message "Gathering all Member of objects" | |
$Groups = (Get-ADGroup -Identity $Identity -Properties *).Memberof | |
} | |
PROCESS { | |
foreach ($Group in $Groups) { | |
Try { | |
Write-Verbose -message "Adding $Group as member" | |
Add-ADGroupMember -Identity $Identity -Members $Group | |
Write-Verbose -message "Removing $Group from Member of" | |
Remove-ADGroupMember -Identity $Group -Members $Identity -Confirm:$false | |
} | |
Catch [Microsoft.ActiveDirectory.Management.ADException] { | |
Write-Warning -message "$Group was already a member of $Identity" | |
Write-Verbose -message "Removing $Group from Member of" | |
Remove-ADGroupMember -Identity $Group -Members $Identity -Confirm:$false | |
} | |
} | |
} | |
END { | |
Write-Verbose -message "Migration of Member of to Member complete" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment