PowerShell / PSDscResources

MIT License
129 stars 53 forks source link

WindowsOptionalFeature: Get Method fails if OptionalFeature has no custom properties when called by the LCM. #191

Open jambar42 opened 4 years ago

jambar42 commented 4 years ago

When the WindowsOptionalFeature DSC resource Get method is invoked by the LCM, an error is thrown if the Optional Feature has no custom properties.

Optional Feature with Custom Properties: PS C:\Windows\system32> Invoke-DscResource -Name "WindowsOptionalFeature" -Method Get -ModuleName "PSDSCResources" -Property @{Name = "SystemDataArchiver"; Ensure = 'Present'}

ConfigurationName : DependsOn : ModuleName : PSDSCResources ModuleVersion : 2.9.0.0 PsDscRunAsCredential : ResourceId : SourceInfo : CustomProperties : {Name = Description, Value = Provides services to collect and archive Windows Server system data., Path = ServerComponent, Name = DisplayName, Value = System Data Archiver, Path = ServerComponent, Name = Id, Value = 1043, Path = ServerComponent, Name = Type, Value = Feature, Path = ServerComponent...} Description : Provides services to collect and archive Windows Server system data. DisplayName : System Data Archiver Ensure : Present LogLevel : WarningsInfo LogPath : C:\Windows\Logs\DISM\dism.log Name : SystemDataArchiver NoWindowsUpdateCheck : RemoveFilesOnDisable : PSComputerName : localhost BeforeChangeWithCustomProperties

Optional Feature without Custom Properties: PS C:\Windows\system32> Invoke-DscResource -Name "WindowsOptionalFeature" -Method Get -ModuleName "PSDSCResources" -Property @{Name = "HypervisorPlatform"; Ensure = 'Present'} A general error occurred that is not covered by a more specific error code.

Windows\Desired State Configuration Event Error 4250 thrown: Job {FCA666F0-D06E-11EA-AD33-248A07A40AF1} : Message Specified cast is not valid. HResult -2147467262 StackTrack at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.ConvertCimInstanceToHashTable(CimInstance cimInstance, Boolean bWrap) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.ConvertCimInstanceToHashTable(CimInstance cimInstance, Boolean bWrap) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.ConvertCimInstanceToHashTable(CimInstance cimInstance, Boolean bWrap) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.GetJsonStringArrayStatusValue(Object value, IntPtr& statusInstanceHandle, UInt32& getActionStatusCode) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.AddSendStatusParametersFromStatusInformation(PowerShell powershell, IntPtr statusInformationPtr, UInt32 reportType, IntPtr& errorInstanceHandle, UInt32& getActionStatusCode) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DownloadManagerBase.SendStatusReport(IntPtr metaConfigHandle, IntPtr& errorInstanceHandle, IntPtr statusInformation, UInt32 reportType, UInt32& getActionStatusCode) DSCEvent4250