Link to home
Start Free TrialLog in
Avatar of rov17
rov17

asked on

PowerShell script to move computer accounts to an OU

Hi
I need a power shell script to move computers accounts (that list in an txt) from all over the domain to another OU.
The txt will have the computer netbois name
I already have vbs but it has only move some machines and left the rest for no reason.
Thanks
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


If you grab the Quest PowerShell CmdLets this will be very easy:

http://www.quest.com/powershell/activeroles-server.aspx

It should let you do this:

Get-Content SomeFile.txt | %{
  Get-QADComputer | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdomain,DC=com"
}

HTH

Chris
Avatar of rov17
rov17

ASKER

Hi Chris,

Thanks for the update, I have Quest PowerShell installed on the server, after running the script I got error message:
The term Get-QADComputer is not recognized as a cmdlet, function, operable program or script file. verify the term and try again

I have got ActiveRoles Management Shell 1.3.0, a part of Quest activeRoles Server 6.5.
 

Hmm are they loaded?

Run this then try again?

Get-PsSnapIn -Reg | Add-PsSnapIn

Chris

Although I did make a mistake in the script. It should have been this (I've added the line to load the snap-in as well:

Add-PsSnapIn Quest.ActiveRoles.ADManagement
Get-Content SomeFile.txt | %{
  Get-QADComputer $_ | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdomain,DC=com"
}

Otherwise it doesn't get the computer name which wouldn't do at all.

Chris
Avatar of rov17

ASKER

Hi Chris,
Yes it worked this time, but it acually didn't read the computer accounts from file, it has moved the machines form Computers OU.
Does the file has to have a header?  

No, you need the modified version I posted above since I failed to include $_ which represents the current line from  the text file. Sorry about that, Monday morning appears to be pushing it a little today.

Chris
Avatar of rov17

ASKER

So should be as below:

Add-PsSnapIn Quest.ActiveRoles.ADManagement
Get-Content $_  SomeFile.txt | %{
  Get-QADComputer $_ | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdomain,DC=com"
}
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rov17

ASKER

Something wrong Chris
The script did move the accounts that in the file to the destenation OU, then it starts to move all the computers accounts and the servers to the same ou (which is not in the file)
the file only had 130 account and I have managed to stop the script after it has moved over 300 machines.

Are there any blank lines in the text file? A trailing blank line will possibly cause that behaviour.

Chris
Avatar of rov17

ASKER

The script has moved the accounts, but then starts to move every thing to the target OU, no empty lines in the file.
Thanks for your help.