3 minute read

When we deploy a set of ESXi’s most of the times we endup enabling SSH and ESXi shell to help troubleshooting.

But that simple tweak leaves a warning in each of the ESXi’s.

SSH/Shell Warning Example

This is a pretty simple manual task since it will be just a question of going through each of the ESXi’s in vCenter and click suppress.

But while is a quick task when it is a small cluster, it could become a repetitive task when you are deploying multiple ESXi’s through some an automated deployed process.

Let us put some Powershell lines together to suppress the warnings in multiple ESXi’s in one go.

PowerCLI cmdlets - Set-AdvancedSetting and Get-AdvancedSetting

We will use cmdlets:

Host Advanced Setting to change

To suppress the alerts/warnings we will need to change UserVars.SuppressShellWarning .

Checking host Advanced Setting current value

To check the current value in each hypervisor of a cluster we can quickly use Get-AdvancedSetting cmdlet:

$cluster = Get-Cluster -Name <Cluster Name>

Write-Host "> Cluster - $cluster" -ForegroundColor Red

$hosts = $cluster | Get-VMHost

foreach($hyp in $hosts) {
    Write-Host "-> Host -> $hyp" -ForegroundColor Yellow

    # Suppress SSH/Shell Warnings
    $currentStatus = Get-AdvancedSetting `
        -Entity (Get-VMHost -Name $hyp.Name) `
        -Name UserVars.SuppressShellWarning

    Write-Host "##> Suppress SSH/Shell Warnings " `
        "- Current Status = $currentStatus" -ForegroundColor Cyan
}

A quick check to validate the current setting status:

Check setting current status Example

Changing the setting

We can use Set-AdvancedSetting cmdlet to change the advanced setting to suppress the warnings.

    # Suppress SSH/Shell Warnings
    $currentStatus = Get-AdvancedSetting `
        -Entity (Get-VMHost -Name <ESXi Name>)  `
        -Name UserVars.SuppressShellWarning

    Write-Host "##> Suppress SSH/Shell Warnings " `
        "- Current Status = $currentStatus" -ForegroundColor Cyan

    # Setting AdvancedSetting to 1
    #   0 = No Suppression
    #   1 = Suppress warnings
    $null = $currentStatus | `
        Set-AdvancedSetting -Value 1 -Confirm:$false

    $lastStatus = Get-AdvancedSetting `
        -Entity (Get-VMHost -Name <ESXi Name>)  `
        -Name UserVars.SuppressShellWarning

    Write-Host "##> Suppress SSH/Shell Warnings " `
        "- Last Status = $lastStatus" -ForegroundColor Green

Let us change the setting and check the result after:

Change Setting Example

ESXi suppressed warnings/alerts:

ESXi Warnings/Errors Example

Getting a quick script together

param(
    [Parameter(Position=1, Mandatory = $true, `
        ValueFromPipeline = $true)] [string]$vcenter,
    [Parameter(Position=2, Mandatory = $true, `
        ValueFromPipeline = $true)] [string]$username,
    [Parameter(Position=3, Mandatory = $true, `
        ValueFromPipeline = $true)] [System.Security.SecureString]$password
)

Write-Host "-> Connect to site $vcenter" -ForegroundColor Green

$vcenterConnection = Connect-VIServer -Server $vcenter `
    -User $username `
    -Password ([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)))

$clusters = Get-Cluster -Server $vcenterConnection

foreach($cluster in $clusters) {
    Write-Host "--> Cluster - $cluster" -ForegroundColor Green

    $hosts = Get-Cluster -Name $cluster | Get-VMHost

    foreach($hyp in $hosts) {
        Write-Host "---> Host -> $hyp" -ForegroundColor Green

        # Suppress SSH/Shell Warnings
        $statusBefore = Get-AdvancedSetting `
            -Entity (Get-VMHost -Name $hyp.Name) `
            -Name UserVars.SuppressShellWarning

        $null = $resultBefore | `
            Set-AdvancedSetting -Value 1 -Confirm:$false

        $statusAfter = Get-AdvancedSetting `
            -Entity (Get-VMHost -Name $hyp.Name) `
            -Name UserVars.SuppressShellWarning

        Write-Host "---# Suppress SSH/Shell Warnings - Status = " `
            "Before:$(($statusBefore).Value) - " `
            "After:$(($statusAfter).Value)" -ForegroundColor Red
    }
}

Disconnect-VIServer -Server $vcenterConnection `
    -Confirm:$false -ErrorAction SilentlyContinue