We're reviewing our code and are trying to replace the WMI CmdLets with the CIM ones. The following code works fine:
$Query = "SELECT InstalledLocation,ProductVersion,ProductName FROM SMS_R_System
JOIN
SMS_G_SYSTEM_Installed_Software on SMS_R_System.ResourceID =
SMS_G_SYSTEM_Installed_Software.ResourceID
WHERE SMS_R_SYSTEM.Name=""$C"" "
Get-WmiObject -ComputerName $SCCMServer -Namespace $SCCMNameSpace -Query $Query
Because WMI uses DCOM by default we thought it was as easy as using the following instead:
$CimSessionOption = New-CimSessionOption –Protocol DCOM
$CimSession = New-CimSession -ComputerName $SCCMServer -SessionOption $CimSessionOption
Get-CimInstance -CimSession $CimSession -Namespace $SCCMNameSpace -Query $Query
But we receive the error New-CimSession : Access denied
although we're using the same connection protocol.
Is there something obvious we're missing here?