dlwyatt / PolicyFileEditor

PowerShell functions and DSC resource wrappers around the TJX.PolFileEditor.PolFile .NET class.
Apache License 2.0
189 stars 33 forks source link

How do I escape backslashes in keyValuename when using cAdministrativeTemplateSetting DSC resource? #21

Open techsnav opened 3 years ago

techsnav commented 3 years ago

Hi Dave, I'm running into an issue when using PolicyFileEditor with DSC:

For eg, the script below works fine, sets the Group Policy as expected: $UserDir = "$env:windir\system32\GroupPolicy\Machine\Registry.pol" $RegPath = 'Software\Policies\Microsoft\Windows\NetworkProvider\HardenedPaths\' $RegName = '\*\NETLOGON' # Backslash Backslash Asterisk Backslash NETLOGON $RegData = 'RequireMutualAuthentication=1, RequireIntegrity=1, RequirePrivacy=1' $RegType = 'String' Set-PolicyFileEntry -Path $UserDir -Key $RegPath -ValueName $RegName -Data $RegData -Type $RegType gpupdate

But not sure how to include "\*\NETLOGON" as ValueName for Key 'Software\Policies\Microsoft\Windows\NetworkProvider\HardenedPaths\' when using in DSC? I've tried it in few different ways, but couldn't get it working.

cAdministrativeTemplateSetting 'Hardened UNC Paths NETLOGON' { KeyValueName = "Software\Policies\Microsoft\Windows\NetworkProvider\HardenedPaths\$([char]0x005C)$([char]0x005C)*$([char]0x005C)NETLOGON" PolicyType = 'Machine' Data = 'RequireMutualAuthentication=1, RequireIntegrity=1, RequirePrivacy=1' Ensure = 'Present' Type = 'String' }

Appreciate your help!!!

techsnav commented 3 years ago

HardenedUNCPath

techsnav commented 3 years ago

Apologies, if I wasn't clear, but this setting is under Administrative Templates:

Computer Configuration\Policies\Administrative Templates\Network\Network Provider\Hardened UNC Paths

Thanks.