Reputation: 631
I am trying to move the below machines to other OUs I have a csv like this:
And I am trying to move them with the code below:
$computers = Import-Csv 'C:\Reports\Win7.csv'
foreach ($computer in $Computers) {
Move-ADObject -Identity $computer.Name -TargetPath "OU=Disabled, OU=Computers, OU=Resources ,DC=hello,DC=world,DC=loc"
}
But I don't know why I get the following error :
Move-ADObject : Cannot find an object with identity: 'WSJ0HZ45J' under:
Which is strange because I can find this machine in AD ..
Any suggestions?
Update
I think i know why it did not worked
I did as below and it helped!
$computers = Import-Csv 'C:\Reports\Win7.csv'
$BaseOU = "OU=Disabled,OU=Computers,OU=Resources,OU=DataManagement,DC=hello,DC=world,DC=loc"
foreach ($computer in $computers) {
Get-adcomputer $computer.Name | Move-ADObject -TargetPath $BaseOU
}
Thanks for help anyway!
Upvotes: 0
Views: 4323
Reputation: 5584
You are feeding the -Identity parameter a canonical computer name. Per Microsoft, the only acceptable values for -Identity parameter are:
Please change your code snippet to the DN value of the computer name and it should work. Below is an example for the one machine based on my guess of where it is in Active Directory. Change computer name to a variable accordingly inside of your script.
Move-ADObject -Identity "DN=WSJ0HZ45JOU,OU=Computers,OU=Resources,DC=hello,DC=world,DC=loc" -TargetPath "OU=Disabled,OU=Computers,OU=Resources,DC=hello,DC=world,DC=loc"
Upvotes: 1