Qwedsa182 Posted June 21, 2017 Posted June 21, 2017 Hi I'm in need of a bit of help, we are trying to move around 1000 computers from under the ou of one place example:Site into multiple ou's within ad. For example everything is currently under "site" but we would like to break it down into room numbers for troubleshooting. Example: Site >Admin >Staffroom1 >Students >Classroom1 Does anyone know if it is possible to do this with a csv and PS ? for example: a csv or text file with and then use powershell to move the 1000 computers ? [TABLE=width: 500] [TR] [TD]Name[/TD] [TD]OU[/TD] [/TR] [TR] [TD]computer1[/TD] [TD]room101[/TD] [/TR] [TR] [TD]computer2[/TD] [TD]room102[/TD] [/TR] [/TABLE] Many thanks for any help. Phil
Ric_ Posted June 22, 2017 Posted June 22, 2017 A quick Google found a super simple script https://gallery.technet.microsoft.com/scriptcenter/Move-AD-Computer-Object-4ed2c5f8 It's not exactly what you want. You could simply create multiple files (one for each destination OU) or you could easily hack it to update the destination variable within the for loop. PowerShell is great
Qwedsa182 Posted June 22, 2017 Author Posted June 22, 2017 Hi Ric So i'd seen that one but was hoping for something to find both within one csv
chrispounds Posted June 22, 2017 Posted June 22, 2017 (edited) Hi Qwedsa, You can import the data using Import-CSV. Each one of the rows is treated as an object, you can target specific columns also. So you could store the new OU into the CSV, then with the script Ric provided, adapt that to your needs. powershell.org is a great place to seek help if you require it But, here is a script that should do it, obviously you need to change the variables to match your scenario $ComputersPath= Import-Csv -Path "D:\Files\Computers.csv" $TargetOU = "OU=NewOU,DC=myDomain,DC=local" foreach ($item in $ComputersPath){ $computer = Get-ADComputer $item.CompName Move-ADObject -Identity $computer.DistinguishedName -TargetPath $TargetOU -Confirm:$false Write-Host Computer account $computer.Name has been moved successfully } What this is doing, is reading column names from the CSV file, so where it says $item.CompName - this is because the column name in the CSV has a title of CompName. Then all of the PC's that need targeting are written below it. Edited June 22, 2017 by chrispounds
chrispounds Posted June 22, 2017 Posted June 22, 2017 If you want to "test run" the script, add -whatif after the "move-adobject" line and it will simulate the action for you first. Then just remove it and re-run it when you are happy.
dapaulio Posted June 29, 2017 Posted June 29, 2017 here is a simple one liner that help moving users from one ou to another Search-ADAccount –AccountDisabled –UsersOnly –SearchBase “OU=sites,DC=domiain,DC=co,DC=uk” | Move-ADObject –TargetPath “OU=Room1,OU=Sites,DC=domain,DC=co,DC=uk” This one liner is to move disabled user accounts out of one ou to another Slightly adapting the searchbase you can target computers that are named like *room1-* in the same way
dapaulio Posted June 29, 2017 Posted June 29, 2017 to be honest for 1000 computers in 1 ou it is probably more time consuming automating it then it would be to drag and drop. granted if you had 1000 computers within a complex ou structure already then I would probably also look to automating it
HPlum78 Posted June 29, 2017 Posted June 29, 2017 If you have already done the piece of work around getting the computer name to OU mapping in to a csv file then the following would do it:- [array]$WksToOu = Import-Csv .\WksToOUs.csv $WksToOu | %{ Get-ADComputer $_.ComputerName | Move-ADObject -TargetPath $_.TargetOU } The CSV would look like this:- ComputerName,TargetOU IT-2276,"OU=W10,OU=StaffPC,OU=Workstations,DC=YOURDOM,DC=XX,DC=XX,DC=XX" TestPC2,"OU=Room2,OU=StudentPC,OU=Workstations,DC=YOURDOM,DC=XX,DC=XX,DC=XX" TestPC3,"OU=W10,OU=StudentPC,OU=Workstations,DC=YOURDOM,DC=XX,DC=XX,DC=XX" TestPC4,"OU=W10,OU=StudentPC,OU=Workstations,DC=YOURDOM,DC=XX,DC=XX,DC=XX" I will add as always some notes around this sort of script, although the above code will do the job (as will the code further up) if I was approaching this I would have it in a try/ catch and have some error trapping and the like. Also any code that has write-host in it needs these instantly changing to write-output as you can do something with the output, no one really runs scripts in the console....
Qwedsa182 Posted July 24, 2017 Author Posted July 24, 2017 Hey all thanks for the replies, we got it sorted in the end and just manually did the majority of them but any bulk computer moves for classrooms we used the script.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now