Closed ricardogaspar2 closed 7 years ago
Out of curiosity, what happens if you call Invoke-DscResource with [Microsoft.Win32.RegistryValueKind]::String
as the argument instead of "String"
? The String-to-Int mapping in the schema file is what happens when you declare a function argument as an enum type in the tooling that I use to auto-generate schema.mof files.
Test 1
$DscParams3 = @{}
$DscParams3.Add("Ensure", "Present")
$DscParams3.Add("KeyValueName", "'SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\LicenseServers")
$DscParams3.Add("PolicyType", "Machine")
$DscParams3.Add("Data", @("something.contoso.com"))
$DscParams3.Add("Type", [Microsoft.Win32.RegistryValueKind]::String)
Invoke-DscResource -Name cAdministrativeTemplateSetting -ModuleName "PolicyFileEditor" -Method Test -Property $dscparams3
Output:
Invoke-DscResource : Failed to serialize properties into CimInstance.
At line:1 char:1
+ Invoke-DscResource -Name cAdministrativeTemplateSetting -ModuleName " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-DscResource], SerializationException
+ FullyQualifiedErrorId : System.Runtime.Serialization.SerializationException,Microsoft.PowerShell.DesiredStateConfiguration.Commands.InvokeDscRe
sourceMethodCommand
Test 2
$DscParams4 = @{}
$DscParams4.Add("Ensure", "Present")
$DscParams4.Add("KeyValueName", "'SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\LicenseServers")
$DscParams4.Add("PolicyType", "Machine")
$DscParams4.Add("Data", @("something.contoso.com"))
$DscParams4.Add("Type", "[Microsoft.Win32.RegistryValueKind]::String")
Invoke-DscResource -Name cAdministrativeTemplateSetting -ModuleName "PolicyFileEditor" -Method Test -Property $dscparams4
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
Added a pull request. The sint32 conversion didn't really make sense indeed.
@dlwyatt if you have time could you push a new version to PSGallery?
V3.0 has been published. Thanks! :)
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 (https://github.com/dlwyatt/PolicyFileEditor/issues/4), using a DSC configuration script works:
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
Output:
This WORKS
Output:
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 integersint
orsint32
.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.