1

I have MDT 2013 deploying several images. With Powershell I would like to move them to the correct OU as well. Is that possible?

I was trying with the following but it does not seem to work:

Enable-PSRemoting -Force
Move-ADObject -Identity $env:COMPUTERNAME -TargetPath ="CN=$($env:COMPUTERNAME),OU=Servers,OU=1,OU=2,OU=3,OU=4,DC=inside,DC=kinux,DC=com"
Invoke-GPUpdate –Computer $env:COMPUTERNAME –RandomDelayInMinutes 0
Jason
  • 3,821
  • 17
  • 65
  • 106
  • Remove the `CN=$($env:COMPUTERNAME)` part from the `-TargetPath`. `-TargetPath` is not the full DN, but only the path to the new parent – Mathias R. Jessen Jan 05 '15 at 10:13
  • Noting that you are trying to do this from MDT. So I am assuming you are doing this from the task sequence which deploys the computer? Move-ADobject is a part of the ActiveDirectory Powershell Module, which is not available by default. Also the command probably runs as the SYSTEM-account, which in turn will require the computer object to be allowed to move itself in AD - or use a runas-account. – Zerqent Mar 25 '15 at 08:51

1 Answers1

1

The -TargetPath parameter on the Move-ADObject Cmdlet is the LDAP path to a container or organizational unit (OU) that you want to put the object in. CN= is the common name of the actual object not the OU, so this part of the LDAP path needs to be removed.

This can be seen by Get-Help Move-ADObject -Detailed.

In your example the script with use:

Move-ADObject -Identity $env:COMPUTERNAME -TargetPath "OU=Servers,OU=1,OU=2,OU=3,OU=4,DC=inside,DC=kinux,DC=com";
Bernie White
  • 1,024
  • 7
  • 17