Moving objects from one OU to another
Often, Active Directory objects are moved between different OUs for reorganization purposes. The following script searches the AD for the given objects and moves them to the mentioned OU target. This script works for user, computer, and group object types:
Function Move-ObjectsToOU { [CmdletBinding()] param( [Parameter(Mandatory=$true,Position=0)] [string[]]$Name, [Parameter(Mandatory=$true,Position=1)] [ValidateSet("User","Group","Computer")] [string]$Type, [Parameter(Mandatory=$true,Position=2)] [string]$TargetOUPath ) if([ADSI]::Exists("LDAP://{0}" -f $TargetOUPath)) { Foreach($ObjectName in $Name) { try { $Object = Get-ADObject -Filter { Name -eq $ObjectName -and ObjectClass -eq $Type } -EA Stop Move-ADObject -Identity $Object -TargetPath $TargetOUPath - EA Stop Write-Host "$ObjectName : Moved successfully to target OU" } catch { Write-Warning "Cannot move $ObjectName"} } } else { Write-Warning...