Escape and preserve double quotes inside OU parameter in admt command

Ammu Shiri Krishnan 1 Reputation point
2022-11-29T08:53:29.333+00:00

I am testing group migration using ADMT cmd line, but the migration is failing for a specific case when the OU name contains double quotes.

Cmd: ADMT GROUP /n "TestGroup" /sourcedomain:Child.A.COM /sourcedomaincontroller:DC2.CHILD.A.COM /targetdomain:A.COM /targetdomaincontroller:DC1.A.COM /targetou:"ParentOU/TEST!@#$%^&*()_+{}|:"<>?[]\;',./" /intraforest:yes /migratesids:yes /migratemembers:no /fixgroupmembership:yes

Error: Unable to migrate groups. Unable to bind to container 'ParentOU/TEST!@#$%^&()_+{}|:<>?[]\;',./ /intraforest:yes /migratesids:yes /migratemembers:no /fixgroupmembership:yes'. Unable to get distinguished name for 'A.COM/ParentOU/TEST!@#$%^&()_+{}|:<>?[]\;',./ /intraforest:yes /migratesids:yes /migratemembers:no /fixgroupmembership:yes'. : The parameter is incorrect. (0x80070057)

I have tried escaping the double quotes with "", ^", \", `" but nothing seems to work. The same is working if I create another OU with same name except for the double quotes.

Please help in resolving this issue.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,187 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,448 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,671 Reputation points
    2022-11-29T15:47:30.19+00:00

    Shell quoting is always a problem. What are you using as a shell, CMD.com or PowerShell.exe? Since you have a windows-server-powershell tag in your question, I'll assume it's PowerShell.

    Try placing a back-tick character before the interior double-quote, or put the targetou value into a variable and using the back-tick in the string value. Then use the variable as the targetou value:

    $p = "ParentOU/TEST!@#$%^&*()_+{}|:`"<>?[]\;',./"  
      
    ADMT GROUP /n "TestGroup" /sourcedomain:Child.A.COM /sourcedomaincontroller:DC2.CHILD.A.COM /targetdomain:A.COM /targetdomaincontroller:DC1.A.COM /targetou:"$p" /intraforest:yes /migratesids:yes /migratemembers:no /fixgroupmembership:yes  
    

    You may have to experiment with the number of double-quotes surrounding the targetou value as each pass through a shell removes one level of quotations.

    0 comments No comments