ESXi get CIM via vCenter PowerCLI

Get ESXi CIM via vCenter with PowerCLI.

Update 07/12/2015:Add parameter MaxEnvelopeSizeKB
Default value was too small while working with “OMC_DiscreteSensor” and end up with the error:
Get-CimInstance : The response that the WS-Management service computed exceed the internal limit for envelope size.

There are already many great resources on how to obtain ESXi CIM information.
I have combined many of them to create the script below.


function Get-VMhostCimInstance{
This function use a PowerCLI vmhost, member of a vCenter server, as a parameter and return a CimInstance.

Author: Christophe Calvet
Based on scripts from Luc Dekens / Alan Renouf / Carter Shanklin 
.PARAMETER Namespace
Specifies the namespace of the class for the new instance. 
The default namespace is root/cimv2. 

One or many PowerCli VMHost object

Specifies the name of the CIM class of which the operation creates an instance. 

Switch: Indicates that when connecting over HTTPS, the client does not validate that the server certificate is signed by a trusted certification authority (CA).

Switch: Indicates that the certificate common name (CN) of the server does not need to match the hostname of the server.

.PARAMETER SkipRevocationCheck
Switch: Indicates that the revocation check for server certificates is skipped.

.PARAMETER MaxEnvelopeSizeKB
Specifies the size limit of WsMan XML messages for either direction.

get-vmhost "MyHost" | Get-VMhostCIMInstance -ClassName "VMware_Privilege"
get-vmhost "MyHost" | Get-VMhostCIMInstance -ClassName "OMC_Chassis" -SkipCACheck -SkipCNCheck -SkipRevocationCheck
(get-vmhost "MyHost" | Get-VMhostCIMInstance -namespace 'root/interop' -ClassName "CIM_RegisteredProfile" -SkipCACheck -SkipCNCheck -SkipRevocationCheck).CimSystemProperties
  [string]$Namespace = 'root/cimv2',
  [uint32]$MaxEnvelopeSizeKB = 1024
			$SessionID = ($VMhost.extensiondata.AcquireCimServicesTicket()).sessionID
			$password = $SessionID  | ConvertTo-SecureString -asPlainText -Force
			$username = $SessionID
			$PSCredential = New-Object System.Management.Automation.PSCredential ($username, $password)
			$CimSessionOptionParameters = @{
			Encoding = 'Utf8'
			UseSsl = $true
			MaxEnvelopeSizeKB = $MaxEnvelopeSizeKB
			$CimSessionOption = New-CimSessionOption @CimSessionOptionParameters
			$Session = New-CimSession -Authentication Basic -Credential $PSCredential -ComputerName $VMhost -port 443 -SessionOption $CimSessionOption
				Switch -wildcard($ClassName){
					"VMware_*" {$ResourceUri = "$ClassName"} 
					"OMC_*" {$ResourceUri = "$ClassName"} 
					"CIM_*" {$ResourceUri = "$ClassName"}			

			Get-CimInstance  -CimSession $Session -Namespace $Namespace -ResourceUri $ResourceUri
		  Write-error $_

Key concepts:
Parameter $VMhost
It must be a VMHostImpl object, in others words a VMHost object returned by Get-VMhost
ValueFromPipeline=$true so it is possible to use this function in this way for example

get-cluster "MyCluster" | get-vmhost | Get-VMhostCIMInstance -ClassName "OMC_Chassis" -SkipCACheck -SkipCNCheck -SkipRevocationCheck

Based on CIM PowerShell cmdlets

This is normally used for CIM authentication for Lockdown Mode.
However this is also very convenient to obtain CIM information for ESXi hosts connected to vCenter instead of individual connection to each ESXi host.

PowerShell Splatting
In this script used with $CimSessionOptionParameters.
I discovered this in a script from Luc Dekens. (Please refer to resources)
This is actually very handy and a good reason to not focus only on PowerCLI ressources but learn as much as possible from PowerShell as well.

Switch -wildcard($ClassName)
Prevent many if/else.

This is based on WS-Management Resource URI

What ClassName are available?
From a VMware point of view please refer to VMware CIM SMASH/Server Management API Reference
Some third party products will also add new ClassName / Namespace. I am doing investigation on this topic but in the meantime it will be necessary to obtain information from third party vendors.

Listing Registered Profile
Listing Registered Profile is possible with:

(get-vmhost "MyHost" | Get-VMhostCIMInstance -namespace 'root/interop' -ClassName "CIM_RegisteredProfile" -SkipCACheck -SkipCNCheck -SkipRevocationCheck).CimSystemProperties

VMware documentation
Luc Dekens
Alan Renouf
Carter Shanklin

Next challenge:
Find a way to list all ClassName available in a Namespace.
It should be possible in one way or another.The VMware CIM Browser Guide
Get-CimClass doesn’t seem to work in this context unfortunately.

3 thoughts on “ESXi get CIM via vCenter PowerCLI

  1. Pingback: PowerCLI study guide from rookie to guru - TheCrazyConsultant

  2. Pingback: PowerCLI study guide – core concepts - The Crazy Consultant

  3. Joschua

    Authentication against ESXi 6.5U1 doesn’t work anymore. I’ve get always Permission denied from New-CimSession. 6.0 Hosts are wokring fine in the same vCennter 6.5U1. Does anyone have an idea?


Leave a Reply

Your email address will not be published. Required fields are marked *