VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

get-wmiobject and get-ciminstance_powershell

Hi Luc,

can you breifelydescribe whats the difference between

get-wmiobjectand get-ciminstance  .

do both of them accpet same     classname  parameters ?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Something like this

$session = New-CimSession -ComputerName <ComputerName>

Get-CimInstance -CimSession $session -ClassName Win32_Service


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

No, the class names largely correspond, the way they are called is different.
In short, the CIM classes are the base classes defined by the Common Information Model.

The WMI classes are how MSFT implemented CIM classes.

You can find a good comparison of both in Should I use CIM or WMI with Windows PowerShell?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks Luc,

As per comparision document  CIM is preffered approach  .

i checked one of the features for remoting uisng cim and i was expecting my prompt changes to remote server (the way enter-pssession  works)as following output seems to suggest iam connected to remote server. but prompt remains on local computer.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that will not change your prompt.

You save the object returned from the New-CimSession call in a variable.

On each subsequent call to a Cim cmdlet, you pass that object via the CimSession parameter.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaksLuc ,

i am trying to get some basic information on remote computer using this command .

i have saved session in $cimobj

iam trying to find what services are running on remote computer .

is this the right way of using cimcomand ??

get-cimclass -ClassName Win32_Service -CimSession $cimobj

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like this

$session = New-CimSession -ComputerName <ComputerName>

Get-CimInstance -CimSession $session -ClassName Win32_Service


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaksLuc .it works .j

ust thought of asking if all three below works on wsman protocol only and winrm service should be running at remote host.

enter-pssession

Get-CimInstance -CimSession $session -ClassName Win32_Service

and

invoke-command

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In PS v6 you can also set up remoting over SSH.
See for example SETUP POWERSHELL SSH REMOTING IN POWERSHELL 6


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

tx i am checking this.

0 Kudos