question

Toror72-4487 avatar image
0 Votes"
Toror72-4487 asked Toror72-4487 answered

New Registry Path with Long Name

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

shashishailaj avatar image
0 Votes"
shashishailaj answered shashishailaj edited

Hello @Toror72-4487 ,

As @RichMatheisen-8856 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 @RichMatheisen-8856 as answer so that it helps other members of the community facing similar issue .

Thank you.




image.png (107.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered RichMatheisen-8856 commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi - I am trying to create a new entry suspect characters such as <> / are reason its failing , I can query the path just cannot add

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"



0 Votes 0 ·

You haven't changed the quoting! Until you do you're doomed to fail.

0 Votes 0 ·
Toror72-4487 avatar image
0 Votes"
Toror72-4487 answered Toror72-4487 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Additionally I can import the key from another PC from both DOS ( reg import) and actual registry editor , however the actual data with value is will not so am thinking if this is Microsoft limitation

0 Votes 0 ·
Toror72-4487 avatar image
0 Votes"
Toror72-4487 answered

Excellent many thanks ! ! !

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.