Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerCLI enable or disable WBEM service on VMware ESXi server

The VMware Host Hardware (WBEM) sensor monitors information about the hardware of an ESXi server using Web-based Enterprise Management (WBEM). This script will disable and enable WBEM service using PowerCLI.

Download this Set-WbemServiceEsxi.ps1 here or it is also available on github.com/janviudapi.

Microsoft PowerShell vmware vsphere esxi vcenter wbem powercli esxcli software service enable disable sendor information automation.jpg

In the core of the script it uses VMware PowerCLI esxcli to modify WBEM service.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function Set-WbemServiceEsxi {
    <#
    .SYNOPSIS
        Disable then enable Wbem service on ESXi Server.
    .DESCRIPTION
        Set-WbemServiceEsxi - Disable then enable Wbem service on ESXi Server. It uses esxcli command to set service
    .PARAMETER ClusterName
        Prompts you to provide cluster name in vCenter server.
    .INPUTS
        System.String
    .OUTPUTS
        System.Object
    .NOTES
        Version:        2.0
        Author:         Janvi
        Creation Date:  10 September 2021
        Purpose/Change: Disable then enable Wbem service on ESXi Server.
        Useful URLs: http://vcloud-lab.com
    .EXAMPLE
        PS C:\>Set-WbemServiceEsxi -ClusterName 'Bat_Cave'
        Disable then enable Wbem service on ESXi Server.
    #>

    # Parameter help description
    [CmdletBinding(HelpUri='http://vcloud-lab.com')]
    [Alias("wbem")]
    param (
        [Parameter(HelpMessage='Type Cluster Name')]
        [Alias('cluster')]
        [System.String]$ClusterName
    )
   
    $esxiServers = Get-Cluster -Name $ClusterName | Get-VMHost -State Connected, Maintenance

    foreach ($esxi in $esxiServers)
    {
        
        $esxcli = $esxi | Get-EsxCLI -V2
        $wbemArgs = $esxcli.system.wbem.set.CreateArgs()
        $wbemArgs.enable = $false
        $disable = $esxcli.system.wbem.set.Invoke($wbemArgs)
        "{0} -->`t`tDisabled: {1} " -f $esxi.Name.PadRight(35, ' '), $disable
        $wbemArgs = $esxcli.system.wbem.set.CreateArgs()
        $wbemArgs.enable = $true
        $enable = $esxcli.system.wbem.set.Invoke($wbemArgs)
        "{0} -->`t`tEnabled: {1} " -f $esxi.Name.PadRight(35, ' '), $enable
    }
}

#Import-Module Vmware.VimAutomation.core
#Connect-VIServer -Server dccomics.vcloud-lab.com -User [email protected] -Password Computer@123

Set-WbemServiceEsxi -ClusterName bat_cave

Additionally you can configure and set below arguments and properties for WBEM service using PowerCLI esxcli command sets.

PS C:\Users\demir\OneDrive> $esxcli.system.wbem.set.CreateArgs()

Name                           Value
----                           -----
httpmaxcontentlength           Unset, ([long], optional)
sslcipherlist                  Unset, ([string], optional)
provprocs                      Unset, ([long], optional)
providertimeoutinterval        Unset, ([long], optional)
threadstacksize                Unset, ([long], optional)
keepalivemaxrequest            Unset, ([long], optional)
httpprocs                      Unset, ([long], optional)
enablehttps                    Unset, ([boolean], optional)
enable                         Unset, ([boolean], optional)
readonly                       Unset, ([boolean], optional)
threadpoolsize                 Unset, ([long], optional)
loglevel                       Unset, ([string], optional)
keepalivetimeout               Unset, ([long], optional)
shutdowninterval               Unset, ([long], optional)
port                           Unset, ([long], optional)
maxmsglen                      Unset, ([long], optional)
protocols                      Unset, ([string[]], optional)
auth                           Unset, ([string], optional)
providersampleinterval         Unset, ([long], optional)
reset                          Unset, ([boolean], optional)
rpoverride                     Unset, ([string], optional)
wsman                          Unset, ([boolean], optional)
httpsprocs                     Unset, ([long], optional)

Useful Articles
POWERCLI AND VSPHERE WEB CLIENT: JOIN ESXI INTO ACTIVE DIRECTORY DOMAIN CONTROLLER
Resolved: Esxi Join domain failed - Error in Active Directory Operations
Join domain ESXi to an Active Directory OU : Powercli

Esxi reset root password, reset windows administrator passwordReset forgotten ESXi root password on Domain joined Esxi using vSphere web client and Powercli
Reset ESXi root password using Host Profiles on vCenter server: VMWare vSphere Web client
Resolved: Reset Esxi forgotten root password using hiren bootCD step by step

PART 1 : INSTALLING ESXI ON VMWARE WORKSTATION HOME LAB 
PART 2 : CONFIGURING ESXI ON VMWARE WORKSTATION HOME LAB 
PART 3 : ACCESSING STANDALONE ESXI SERVER IN HOME LAB USING VSPHERE CLIENT 
Create bootable USB from ISO file

Go Back



Comment

Blog Search

Page Views

12278719

Follow me on Blogarama