New-CimInstance error

Hello! I am using the cWebsite DSC resource to create an IIS website. I have modified the resource, as I need to be able to add net.pipe as a binding to a few of my sites. The set-targetresource portion of the program works great and my sites are created the way I expect with no errors encountered.

While using the get-dscconfiguration command however, I am experiencing an error. For some context, this error is being generated while attempting to return the website bindings. The error message is as follows:

Get-DscConfiguration : Could not infer CimType from the provided .NET object.
At line:1 char:1
+ Get-DscConfiguration
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Manag...InstanceCommand:root/Microsoft/...gurationManager)
   [Get-DscConfiguration], CimException
    + FullyQualifiedErrorId : New-CimInstance,Microsoft.Management.Infrastructure.CimCmdlets.NewCimInstanceCommand,Get
   -DscConfiguration

I have tracked down the offending line of code, as if I remove it I no longer encounter the error:

New-CimInstance -ClassName PSHOrg_cWebBindingInformation -Namespace root/microsoft/Windows/DesiredStateConfiguration -Property @{Port=[System.UInt16]$BindingObject.Port;Protocol=$BindingObject.Protocol;IPAddress=$BindingObject.IPaddress;HostName=$BindingObject.Hostname;CertificateThumbprint=$BindingObject.CertificateThumbprint;CertificateStoreName=$BindingObject.CertificateStoreName} -ClientOnly

If I attempt to run the above command directly on the machine who is receiving the DSC configuration (from a pull server) I get this slightly different flavor of the error message:

New-CimInstance : Could not infer CimType from the provided .NET object.
At line:1 char:1
+ New-CimInstance -ClassName PSHOrg_cWebBindingInformation -Namespace r ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Manag...InstanceCommand:NewCimInstanceCommand) [New-CimInst
   ance], ArgumentException
    + FullyQualifiedErrorId : New-CimInstance,Microsoft.Management.Infrastructure.CimCmdlets.NewCimInstanceCommand

I am somewhat new to using PowerShell in an advanced fashion and am not really sure what this error message is trying to tell me, nor am I really familiar with what the New-CimInstance command is actually doing :frowning: Googling has yielded no helpful results thus far. I am sort of just hitting it with a hammer at this point to see if I can break it in a different way to give me a better clue or magically stumble upon a fix.

Anyway, if anyone knows anything about this error or can educate me on the New-CimInstance command, that would be awesome :slight_smile: If anyone has questions or needs more info, I’ll be happy to share.

Thanks!

The short answer - and we’ll see if anyone jumps in to offer something better - is that PowerShell is have trouble matching up the .NET Framework class to a corresponding CIM class. It’s normally very good at that with the basic stuff, but when you venture into the outer edges, it can get tricky.

It may help to understand that everything in DSC happens via WMI (CIM). So the resources you write get “exposed” via WMI, sort of. So it’s possible that in modifying the resource, you’ve “broken” that connection to WMI, which means when your code tries to create an instance of the resource, it fails.

The fact that the Set- runs fine makes this a bit more elusive. I’ll ping a couple of folks and see if they might have an easier answer.

This works properly in WMF4, but seems to error in WMF5. A quick check of Connect does not show any bug filed around this. I’ve seen reports of this in reverse as well, with xFirewall.

I think most of this type of error is driven from trying to martial types between CIM and .NET.

I filed https://connect.microsoft.com/PowerShell/feedback/details/1721560 for this.

Thanks for the responses! Good to know I’m not completely losing my mind, and I can confirm that all servers in my scenario are running WMF5.