New Registry Path with Long Name

Toror72 21 Reputation points
2020-07-23T23:41:20.457+00:00

Hi All I am trying to add a new registry key which contains a very long value. I can create the registry key :

New-Item "HKLM:SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\Test1.com"

I am trying to add the following value but struggling with syntax - can anyone please help !!!
NOTE - the key is from GPO policy for AppLocker. I found it applied to a domain joined PC and want to use this same value to update the registry for machines that are off the domain.

New-ItemProperty "HKLM:SOFTWARE\Policies\Microsoft\Windows\SrpV2\Exe\11759873-1713-4c87-b95b-925c887337a5" -Name "value" -Value "<FilePublisherRule Id="11759873-1713-4c87-b95b-925c887337a5" Name="MICROSOFT DYNAMICS 365 COMMERCE, from O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" Description="" UserOrGroupSid="S-1-1-0" Action="Allow"><Conditions><FilePublisherCondition PublisherName="O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" ProductName="MICROSOFT DYNAMICS 365 COMMERCE" BinaryName=""><BinaryVersionRange LowSection="" HighSection="*"/></FilePublisherCondition></Conditions></FilePublisherRule>" -PropertyType "String"

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,546 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shashi Shailaj 7,606 Reputation points Microsoft Employee
    2020-07-24T17:50:29.197+00:00

    Hello @Toror72 ,

    As @Rich Matheisen mentioned , you would require to use single quotes with the string .

    New-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Exe\11759873-1713-4c87-b95b-925c887337a5" -Name "Value" -Value '<FilePublisherRule Id="11759873-1713-4c87-b95b-925c887337a5" Name="MICROSOFT DYNAMICS 365 COMMERCE, from O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" Description="R" UserOrGroupSid="S-1-1-0" Action="Allow"><Conditions><FilePublisherCondition PublisherName="O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" ProductName="MICROSOFT DYNAMICS 365 COMMERCE" BinaryName=""><BinaryVersionRange LowSection="" HighSection="*"/></FilePublisherCondition></Conditions></FilePublisherRule>' -PropertyType "String"  
    

    The above works perfectly as you can see it in the output. The reg.exe does not take large values with spaces in the middle as such and hence gives Invalid syntax .

    13692-image.png

    Hope this output helps. If the information is helpful , please do accept post from @Rich Matheisen as answer so that it helps other members of the community facing similar issue .

    Thank you.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Rich Matheisen 46,801 Reputation points
    2020-07-24T02:02:32.127+00:00

    You don't say what problem it is that you're having, but I suspect that it's the string literal you're trying to supply in the "-value" parameter.

    That string contains double quotes and you're trying to surround the string with double quotes. Try changing the beginning and ending double quotes to single quotes.

    1 person found this answer helpful.

  2. Toror72 21 Reputation points
    2020-07-24T07:22:30.22+00:00

    Also I treid DOS and same issue
    C:\windows\system32>reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Exe\11759873-1713-4c87-b95b-925c887337a5" /v Value /t reg_sz /d "<FilePublisherRule Id="11759873-1713-4c87-b95b-925c887337a5" Name="MICROSOFT DYNAMICS 365 COMMERCE, from O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" Description="" UserOrGroupSid="S-1-1-0" Action="Allow"><Conditions><FilePublisherCondition PublisherName="O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US" ProductName="MICROSOFT DYNAMICS 365 COMMERCE" BinaryName=""><BinaryVersionRange LowSection="" HighSection="*"/></FilePublisherCondition></Conditions></FilePublisherRule>"
    ERROR: Invalid syntax.
    Type "REG ADD /?" for usage.

    C:\windows\system32>reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Exe\11759873-1713-4c87-b95b-925c887337a5" /v Value /t reg_sz /d "001"
    The operation completed successfully.


  3. Toror72 21 Reputation points
    2020-07-28T00:28:26.667+00:00

    Excellent many thanks ! ! !

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.