Wiktor
Wiktor

Reputation: 631

Move-ADObject Cannot find an object with identity

I am trying to move the below machines to other OUs I have a csv like this:

enter image description here

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

Answers (1)

T-Heron
T-Heron

Reputation: 5584

You are feeding the -Identity parameter a canonical computer name. Per Microsoft, the only acceptable values for -Identity parameter are:

  • A distinguished name
  • A GUID (objectGUID)

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

Related Questions