Skip to content

Instantly share code, notes, and snippets.

@briped
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briped/28603d3125e5fe72b99b to your computer and use it in GitHub Desktop.
Save briped/28603d3125e5fe72b99b to your computer and use it in GitHub Desktop.
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