CIM Instead of WMI to discover monitor info

Windows Server 2012 and Windows 8.1 brings new set of Cmdlets to manage any Server or device that complies with CIM. Before months i wrote an article Use WMI with Powershell to Discover Monitor Information but new CmdLets like CIM is more powerfull and can use it instead of WMI. Also after publish the article related to WMI lot of users complaint that can get this info with better way which is the CIM.

Today I will explain how can Discover Monitor Information from Devices or Servers with CIM instead of WMI and how easy is to migrate any script that you have create with WMI related on Discover Monitoring info in CIM.

Before begin i would like to explain what means the letters CIM. CIM = Common Information Mode and base on the explanation in  Scripting Guy Blog  "provides a common definition of management information for systems, networks, applications and services, and allows for vendor extensions. CIM's common definitions enable vendors to exchange semantically rich management information between systems throughout the network."

Now i will ask the question why to use CIM and not continue with WMI?

Because

  • WMI don't provide first class PS Experience,
  • There are issues with serializing a WMI object,
  • there is no concept of session reuse and WMI object has weird looking property names (like __Server)
  • And more more in Windows Powershell Blog

Instead with CIM can

  • Make CIM a first class citizen of PS
  • Should be able to  manage any CIM+WsMan device
  • Support down-level machines

 

Now it's time to proceed and DIscover Monitoring Info from Devices. Read the article Use WMI with Powershell to Discover Monitor Information to understand how will proceed.

  • Check if can connect remotely with Powershell in devices that you want to get Monitoring Info. Read the How to Manage PC or Servers Remotely with Powershell
  • Let's take the  the Hard Disk Info. Type the command
    Get-CIMInstance Win32_Logicaldisk -filter "deviceid='C:'" -Computer ktzouvaras

  • Take the Cpu Type of the Workstation
    Get-CIMInstance Win32_processor  -Computer ktzouvaras

  • What about RAM?
    Get-CIMInstance Win32_physicalmemory  -Computer ktzouvaras

  • Do you get lot of Info?
    Get-CIMInstance Win32_physicalmemory   -Computer ktzouvaras | Select Capacity.

  • These are some of the commands that you can run. If you want to migrate any script with WMI to CIM you can go in Windows PowerShell Blog and open the Article Introduction to CIM Cmdlets go down and found the 7. Easy migration from WMI cmdlets.
  • In the article that i wrote before months Use WMI with Powershell to Discover Monitor Information i have publish a small script to get discovery info from a PC without need to run multiple commands.
  • Let's take a look. This is the old script

    -------------------------------------------------------------------------------------------------------------------------------------------------------------

$bios = Get-WmiObject win32_OperatingSystem -ComputerName localhost | Select PSComputername
$Proc = Get-WmiObject Win32_processor -ComputerName localhost | Select-Object -First 1
$memory = Get-WmiObject Win32_physicalmemory -ComputerName localhost
$system= Get-WmiObject Win32_ComputerSystem -ComputerName localhost
$localdisk=Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName localhost

$Object = New-Object PSObject -Property @{
ComputerName           = $proc.SystemName
Model                  = $system.Model
'Processor Number'     = $system.NumberOfProcessors
'Processor Name'       = $proc.name
'Logical Processeur'   = $system.NumberOfLogicalProcessors
'RAM (GB)'             = $system.TotalPhysicalMemory / 1GB -as [int]
'Used RAM slot'        = $memory.count
'Local Disk c'         = $localdisk.size / 1GB -as [int]
}

Write-Output $Object

----------------------------------------------------------------------------------------------------------------------------------------------------------------
         

  • Change the command Get-WmiObject  with Get-CIMInstance and save it.

         -------------------------------------------------------------------------------------------------------------------------------------------------------------

$bios = Get-CIMInstance win32_OperatingSystem -ComputerName localhost | Select PSComputername
$Proc = Get-CIMInstance Win32_processor -ComputerName localhost | Select-Object -First 1
$memory = Get-CIMInstance Win32_physicalmemory -ComputerName localhost
$system= Get-CIMInstance Win32_ComputerSystem -ComputerName localhost
$localdisk=Get-CIMInstance Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName localhost

$Object = New-Object PSObject -Property @{
ComputerName           = $proc.SystemName
Model                  = $system.Model
'Processor Number'     = $system.NumberOfProcessors
'Processor Name'       = $proc.name
'Logical Processor'   = $system.NumberOfLogicalProcessors
'RAM (GB)'             = $system.TotalPhysicalMemory / 1GB -as [int]
'Used RAM slot'        = $memory.count
'Local Disk c'         = $localdisk.size / 1GB -as [int]
}

Write-Output $Object

----------------------------------------------------------------------------------------------------------------------------------------------------------------

This is only simple examples that i write for now. In the future i will go more deep with CIM-Instance and publish more examples that can automate your tasks. I hope to help you and give you something more today in powershell.

If you have something to say I would like to hear your opinions and share it with other user in our Commented System.

Have a nice weekend !!!! 

 

Tags