Wednesday, 10 May 2023

How to move computer object one OU to another OU using PowerShell

 How to move computer object one OU to another OU using PowerShell

File Format :- input.txt




# Specify target OU. This is where Computer will be moved.

$TargetOU = "OU=ADMIN OU,OU=IT Accounts,OU=Support,OU=Administration,DC=abc,DC=com"

# Specify CSV path. Import CSV file and assign it to a variable.

$computers = gc C:\temp\input.txt

$description = "Moved to disabled computer OU | COM786"

foreach($computer in $computers) {

Set-ADComputer -Identity $computer -Description $description

$comdn = (Get-ADComputer $computer).distinguishedName

# Move user to target OU.

Move-ADObject $comdn -TargetPath $TargetOU

Write-Host "$computer moved to $TargetOU"

}


PowerShell Basic, Active Directory PowerShell Command 

No comments:

Post a Comment