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
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
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.
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.ADManage
Get-Content SomeFile.txt | %{
Get-QADComputer $_ | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdo
}
Otherwise it doesn't get the computer name which wouldn't do at all.
Chris
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?
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
ASKER
So should be as below:
Add-PsSnapIn Quest.ActiveRoles.ADManage ment
Get-Content $_ SomeFile.txt | %{
Get-QADComputer $_ | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdo main,DC=co m"
}
Add-PsSnapIn Quest.ActiveRoles.ADManage
Get-Content $_ SomeFile.txt | %{
Get-QADComputer $_ | Move-QADObject -NewParentContainer "OU=SomewhereNew,DC=yourdo
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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.
Thanks for your help.
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=yourdo
}
HTH
Chris