dsccommunity/GPRegistryPolicyDsc

[GPRegistryPolicyFileParser] Error with internationalization in GPRegistryPolicyFileParser submodule

NicolasBn opened this issue · 6 comments

Details of the scenario you tried and the problem that is occurring

I use GPRegistryPolicyDsc through CommonTasks, in french Windows Server 2016.
GPRegistryPolicyDsc contains submodule GPRegistryFileParser that used Import-LocalizedData cmdlet. In french system, this command tried to found GPRegistryPolicyFileParser.strings.psd1 in GPRegistryPolicyDsc\1.2.0\Modules\GPRegistryPolicyFileParser\fr-FR\ folder.

That generated an error in mof compilation.

Verbose logs showing the problem

Suggested solution to the issue

There is only one language-specific data in the submodule. To avoid this problem, we could force the culture en-US in Import-LocalizedData with UICulture parameter.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

# insert configuration here

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Datacenter Evaluation
OsOperatingSystemSKU : 80
OsArchitecture       : 64 bits
WindowsBuildLabEx    : 14393.1944.amd64fre.rs1_release.171129-2100
OsLanguage           : fr-FR
OsMuiLanguages       : {fr-FR}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.14393.1944
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1944
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used

Name                Version Path
----                ------- ----
GPRegistryPolicyDsc 1.2.0   C:\Program Files\WindowsPowerShell\Modules\GPRegistryPolicyDsc\1.2.0\GPRegistryPolicyDsc.psd1

Indeed, that's seems to be a good idea. But is that will not enter in conflict with Get-LocalizedData present in GPRegistryPolicyDsc.Common submodule ?

The functions that exist in GPRegistryPolicyDsc.Common should be removed if the function exist in DscResource.Common. Then the resources should be modified (if necessary) to use the functions in DscResource.common instead of those that was removed.

Only two function are really use in resource : Test-ParameterState and Get-LocalizedData.
GPRegistryPolicyDsc.Common could be completly removed.

Just this part need to be moved in GPRegistryPolicyFileParser.psm1 :

<#
    GetPrivateProfileString and WritePrivateProfileString are functions exposed via kernel32.dll that allow for reading and
    creating/modifying .ini files respectively.  These signatures are defined below and exposed when the module is imported
    to be used in correctly configuring the gpt.ini file in order for Group Policy to be processed successfully.
    Reference:
    GetPrivateProfileString:   https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprivateprofilestring
    WritePrivateProfileString: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-writeprivateprofilestringa
#>

$profileStringSignature = @'
    [DllImport("kernel32.dll")]
    public static extern uint GetPrivateProfileString(
        string lpAppName,
        string lpKeyName,
        string lpDefault,
        StringBuilder lpReturnedString,
        uint nSize,
        string lpFileName
    );

    [DllImport("kernel32.dll")]
    public static extern bool WritePrivateProfileString(
        string lpAppName,
        string lpKeyName,
        string lpString,
        string lpFileName
    );
'@

Add-Type -MemberDefinition $profileStringSignature -Name IniUtility -Namespace GPRegistryPolicyDsc -Using System.Text

I ran into the same problem, could someone merge the PR from @NicolasBn, please.