Hi, I would like to report some issues I found in order to improve this module.
I was trying to use this DSC resource but I had a few issues when using it with Invoke-DSCResource
command.
Although, as I described in a previous issue (#4), using a DSC configuration script works:
Configuration LocalGPO
{
param
(
[string[]] $NodeName = 'localhost'
)
Import-DSCResource -ModuleName PolicyFileEditor
Node $NodeName
{
cAdministrativeTemplateSetting RDPLicensing
{
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\LicenseServers"
PolicyType = "Machine"
Data = ("server.test.localgpo.dsc.com")
Ensure = "Present"
Type = "String"
}
## The next 3 resources are to change the GPO Setting "Set Remote Desktop Services User Home Directory"
cAdministrativeTemplateSetting "RDP Users Home Directory Path"
{
# SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirUNC
# SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDir
# SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirDrive
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDir"
PolicyType = "Machine"
Data = "\\servershare\test"
Ensure = "Present"
Type = "String"
}
cAdministrativeTemplateSetting "RDP Users Home Directory Letter"
{
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirDrive"
PolicyType = "Machine"
Data = "X:"
Ensure = "Present"
Type = "String"
}
cAdministrativeTemplateSetting "RDP Users Home Directory UNC boolean"
{
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirUNC"
PolicyType = "Machine"
Data = "1"
Ensure = "Present"
Type = "Dword"
}
}
}
LocalGPO
Start-DscConfiguration -Path .\LocalGPO -Wait -Force -Verbose
When one needs to remotely call this resource or use other configuration management tools like Puppet or Ansible that rely on the Invoke-DSCResource
command it doesn't work properly.
You can check the reported issues submitted by me in the corresponding issue trackers:
It's possible to confirm that there is a problem when passing the Type
property as a string.
Tests:
This does NOT work
$DscParams = @{}
$DscParams.Add("Ensure", "Present")
$DscParams.Add("KeyValueName", "'SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\LicenseServers")
$DscParams.Add("PolicyType", "Machine")
$DscParams.Add("Data", @("something.contoso.com"))
$DscParams.Add("Type", "String")
Invoke-DscResource -Name cAdministrativeTemplateSetting -ModuleName "PolicyFileEditor" -Method Test -Property $dscparams
Output:
Convert property 'Type' value from type 'STRING' to type 'SINT32' failed
At line:12, char:2
Buffer:
irectResourceAccess";
};^
insta
+ CategoryInfo : SyntaxError: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MiClientApiError_Failed
+ PSComputerName : localhost
This WORKS
$DscParams2 = @{}
$DscParams2.Add("Ensure", "Present")
$DscParams2.Add("KeyValueName", "'SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\LicenseServers")
$DscParams2.Add("PolicyType", "Machine")
$DscParams2.Add("Data", @("something.contoso.com"))
$DscParams2.Add("Type", 1)
Invoke-DscResource -Name cAdministrativeTemplateSetting -ModuleName "PolicyFileEditor" -Method Test -Property $dscparams2
Output:
InDesiredState
--------------
False
With any type the resource only works passing an integer, as defined in the mof file:
https://github.com/dlwyatt/PolicyFileEditor/blob/master/DscResources/PshOrg_AccountAdminTemplateSetting/PshOrg_AccountAdminTemplateSetting.schema.mof#L8
Possible solutions
So, the solutions could be on of the two:
1. [Preferable] Change the type to String
.
Like the Registry resource from Microsoft, it is possible to use a string instead of sint32:
https://github.com/PowerShell/PSDscResources/blob/2c33e69634aa9c641ab27427d457fe9f49884e7c/DscResources/MSFT_RegistryResource/MSFT_RegistryResource.schema.mof#L7
2. Change the map in the type
property to use only integers int
or sint32
.
[ClassVersion("1"), FriendlyName("cAccountAdministrativeTemplateSetting")]
class PshOrg_AccountAdminTemplateSetting : OMI_BaseResource
{
[Key] string Account;
[Key] string KeyValueName;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write] string Data[];
[write,ValueMap{"0","1","2","3","4","7","11","-1"},Values"0","1","2","3","4","7","11","-1"}] sint32 Type;
};
In this solution, the user has to know the mappings from the different types in order to use the correct integer. So it has to be in the documentation somewhere.
It would be great to have a fix for this.