Share via


Trouble using Get-CimInstance instead of Get-WmiObject

Question

Wednesday, June 19, 2019 12:59 PM

I have two identical scripts in Powershell. Only Get-WmiObject is replaced by Get-CimInstance. The Get-WmiObject works as expected but Get-CimInstance does not work. See examples below.

fzDesktop11 is a remote computer

Works
Get-WmiObject -ClassName win32_operatingsystem -ComputerName fzDesktop11 | Select-Object csname, lastbootuptime

**Does not work.**Get-CimInstance -ClassName win32_operatingsystem -ComputerName fzDesktop11 | Select-Object csname, lastbootuptime

Error message:
Get-CimInstance : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
 
Why does Get-WmiObject work and Get-CimInstance does not?
How can I resolve this problem?

Thanks

All replies (4)

Wednesday, June 19, 2019 7:46 PM ✅Answered

Thanks guys.

WinRM was not running on fzDeskto11. Confusion arose because in the past WinRM was running on this machine.

I activated WinRM remotely from Powershell with the following script.

Get-Service -Name winRM -ComputerName fzDesktop11 | Set-Service -Status Running

It is solved


Wednesday, June 19, 2019 1:24 PM

You will have to fix the remote system.  The protocols used by the two commands are different.  The error tells you that WinRM is not running on the remote system.

\(ツ)_/


Wednesday, June 19, 2019 3:16 PM

get-wmiobject uses the dcom protocol and get-ciminstance uses the wsman protocol by default.  Here's some info and a workaround:  https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/use-get-ciminstance-with-dcom


Wednesday, June 19, 2019 7:48 PM

You may have to set the service to auto start.