microsoft / BaselineManagement

Conversion tool used to Convert Group Policy baselines into DSC
MIT License
266 stars 52 forks source link

Exception Parsing Banner and MOTD Strings with Quotes on ConvertFrom-GPO #22

Open ephos opened 5 years ago

ephos commented 5 years ago

We are enforcing legal banners on servers so we set the following keys (I changed the actual values to protect the innocent).

These are the values contained in the GPO backup (.{7C78F02A-DBCF-460D-8C0F-A7B5E8082F5B}\DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit\GptTmpl.inf)

MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=1,"'Legal mumbo jumbo.'"

MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeCaption=1,"'DONT HACK THIS STUFF BRO!'"

When I run ConvertFrom-GPO it throws an exception when it gets to these settings, due to the way they are double quoted and single quoted ("'message'").

This is the exception.

 PS>ConvertFrom-GPO -Path '.\GPObackups\sec_2016\{7C78F02A-DBCF-460D-8C0F-A7B5E8082F5B}\' -OutputPath .\2016\

Method invocation failed because [System.Management.Automation.ErrorRecord] does not contain a method named 'Trim'.
At C:\Users\user\Documents\WindowsPowerShell\Modules\BaselineManagement\2.8.8841\Helpers\Functions.ps1:191 char:42
+ ... g += "@'`n$($_.Trim("'").TrimStart("'").TrimEnd("'").TrimStart('"').T ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I get two of these exceptions, when running through the debugger I can confirm it's on these two items.

If I modify the lines in the GptTmpl.inf and replace the quotes with just single quotes, everything works prefect. In the short term i'll look into getting our legal banner to not have the extra quotes, I'm sure that'll be fine, I wanted to report the issue in case other ran into it.

bobbytreed commented 5 years ago

I'll take a look at the here string logic for this.

Sorry for the hiatus

mgreenegit commented 4 years ago

@bobbytreed is this still an issue?

packerphil commented 3 years ago

I'm using version 3.1.1 of the module, and it is still an issue. Is there any movement on it?

Exception calling "Create" with "1" argument(s): "At line:1288 char:26

Complete-Configuration : Could not CREATE ScriptBlock from configuration. Creating PS1 Error File: D:\GPO-to-DSC\GPO\DSCOutput{D8DAE6FA-3201-4E6D-8271-9A0BF446BEDA}\DSCFromGPO.ps1.error. Please rename error file to PS1 and open for further inspection. Errors are listed below At C:\Program Files\WindowsPowerShell\Modules\BaselineManagement\2.9.0\BaselineManagement.psm1:719 char:17

mgreenegit commented 3 years ago

I can try to help with this one. To help with repro - this occurs when the message contains single quotes? Or am I misunderstanding?