Skip to content

Get-EsxCli

VMware: Exposes the ESXCLI functionality

#Requires -Version 5.1
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [string]$HostName,
    [switch]$V2
)
Process {
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        if ([System.String]::IsNullOrWhiteSpace($HostName)) {
            $result = Get-EsxCli -Server $vmServer -V2:$V2 -ErrorAction Stop | Select-Object *
        }
        else {
            $vmHost = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
            $result = Get-EsxCli -Server $vmServer -V2:$V2 -VMHost $vmHost -ErrorAction Stop | Select-Object *
        }
        if ($null -ne $result) { foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force } }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Name of the host to expose ESXCLI; retrieves from all hosts if empty

Off

Returns ESXCLI object version 2 (V2) instead of version 1

An interactive directory of PowerShell scripts.