Powershell – Moving computers to known OU
While working on our WSUS Policy, i needed to create a script to move computer objects from whatever OU they were in (unknown) to a known OU. I decided to embark on powershell for this. With the help of David Crown from the MSSMS list on myitforum, here is what we came up with.
This script takes a CSV list of computers, target location, and moves the computer objects from wherever they are, to the target location. One of the struggles we had was getting the command to work with a computer object in the csv list that didn’t exist in AD, the final result accounts for this.
Import-Csv 'c:\computer exclusions.csv' | `
Foreach {$computer = get-QADComputer -name $_.computer; `
if ($computer -eq $null) {Write-Output "$_.computer bad object`n"}
else {move-QADObject $computer -to $_.target }
}
CSV format is:
Computer, Target