Last active
August 29, 2015 14:08
-
-
Save briped/28603d3125e5fe72b99b to your computer and use it in GitHub Desktop.
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
Param( | |
[parameter(Mandatory=$true, | |
HelpMessage="Enter AD group to move from.")] | |
[string] | |
$SourceGroup, | |
[parameter(Mandatory=$true, | |
HelpMessage="Enter AD group to move to.")] | |
[string] | |
$TargetGroup | |
) | |
Import-Module -Name ActiveDirectory -ErrorAction SilentlyContinue | |
Get-ADGroupMember -Recursive -Identity $SourceGroup | ForEach-Object { | |
$Error.Clear() | |
Try | |
{ | |
Write-Debug -Message "Add-ADGroupMember -Members $($_.SamAccountName)-Identity $($TargetGroup)" | |
Add-ADGroupMember -Members $($_.SamAccountName) -Identity $($TargetGroup) | |
} | |
Catch | |
{ | |
Write-Warning -Message "An error occurred when attempting to add $($_.SamAccountName)to $($TargetGroup)" | |
} | |
If (!$Error) | |
{ | |
Try | |
{ | |
Write-Debug -Message "Remove-ADGroupMember -Members $($_.SamAccountName)-Identity $($SourceGroup) -Confirm:$false" | |
Remove-ADGroupMember -Members $($_.SamAccountName) -Identity $($SourceGroup) -Confirm:$false | |
} | |
Catch | |
{ | |
Write-Warning -Message "An error occurred when attempting to remove $($_.SamAccountName)from $($SourceGroup)" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment