Read Time:48 Second
This script is for moving the bulk users in a specific OU to another domain in active directory. Compatible with PowerShell version 4.
<# .SYNOPSIS Bulk move computer accounts to specific OU .DESCRIPTION Bulk move computer accounts to specific OU .EXAMPLE .\Move-ComputerAccounts.ps1 #> Remove-Item '.\ADcomputerMove.log' -Ea SilentlyContinue #Get the computer list from the servers.txt file $ComputerAccVar= Get-Content .\computers.txt #Specify the OU Path $TargetOUVar = 'OU=NU,OU=GDSScripts,DC=Sub,DC=Domain,DC=Com' foreach ($server in $ComputerAccVar){ try{ $DNVar= (Get-ADComputer $server).distinguishedname Move-ADObject -Identity $DNVar -TargetPath $TargetOUVar Write-Host "Success: Moved computer account $server to the $TargetOUVar" -ForegroundColor Cyan Out-File -FilePath '.\ADcomputerMove.log' -InputObject "Success:Moved computer account $server to the $TargetOUVar" -Append -ea SilentlyContinue } catch { $ErrorVar= "Failed :" $ErrorVar+=$_.Exception.Message Write-Host "Failed :"$_.Exception.Message -ForegroundColor Yellow Out-File -FilePath '.\ADcomputerMove.log' -InputObject $ErrorVar -Append continue } } Write-host "Script Completed Successfully. Report is available at .\ADcomputerMove.log"