How to Quickly Check/Backup ESXi Host TPM Encryption Recovery Key Using PowerCLI

Managing encryption across multiple ESXi hosts can be a bit of a hassle. But don’t worry. I’ve got a simple PowerCLI script that’ll save you time and headaches by quickly retrieving encryption status and recovery keys from your VMware environment.

Why Do You Need This?

Ensuring your ESXi hosts are correctly encrypted is essential for security. Regular checks help prevent surprises later, especially during troubleshooting or audits.

Getting Started

First, make sure you’re connected to your vCenter:

Connect-VIServer -Server

Replace with your vCenter IP or FQDN.

The Script Breakdown

Here’s a quick rundown of the PowerCLI script to verify encryption settings across all ESXi hosts and who Recovery key for each ESXi host. (link to GitHub repository and file tpm_recovery_key_backup.ps1):

# Connect to your vCenter server (if not already connected)
# Connect-VIServer -Server <VCENTER_IP_OR_FQDN>

$esxis  = get-vmhost | Sort-Object

foreach ($esx in $esxis) {
    $key= @()
    $enc = @()
    if ($esx.ConnectionState -ne "Connected" -and $esx.ConnectionState -ne "Maintenance") {
        Write-Host ""
        Write-Host "================================================================================" -ForegroundColor Yellow
        Write-Host "๐Ÿšซ SKIPPED HOST" -ForegroundColor Yellow
        Write-Host "Host                : $($esx.Name)" -ForegroundColor DarkYellow
        Write-Host "Reason              : Not powered on or disconnected." -ForegroundColor DarkYellow
        Write-Host "================================================================================" -ForegroundColor Yellow
        Write-Host ""
        continue
    }
    $esxcli = Get-EsxCli -VMHost $esx -V2
    try {
        $key = $esxcli.system.settings.encryption.recovery.list.Invoke()
        $enc =  $esxcli.system.settings.encryption.get.Invoke()

        Write-Host "================================================================================" -ForegroundColor DarkCyan
        Write-Host "๐Ÿ”น ESXi Host        : $($esx.Name)" -ForegroundColor Cyan
        Write-Host "๐Ÿ” Recovery ID      : $($key.RecoveryID)" -ForegroundColor Green
        Write-Host "๐Ÿ—๏ธ  Recovery Key     : $($key.Key)" -ForegroundColor Yellow
        Write-Host "๐Ÿ”’ Encryption Mode  : $($enc.Mode)" -ForegroundColor Magenta
        Write-Host "================================================================================" -ForegroundColor DarkCyan
        Write-Host ""
    }
    catch {
        Write-Host ""
        Write-Host "================================================================================" -ForegroundColor DarkGray
        Write-Host "โŒ ERROR for host    : $($esx.Name)" -ForegroundColor Red
        Write-Host "โš ๏ธ  Failed to get encryption key for $($esx.Name) ."
        Write-Host "๐Ÿงจ Error details     : $_"
        Write-Host "================================================================================" -ForegroundColor DarkGray
        Write-Host ""
    }
}

What the Script Does

  • Connects to each ESXi host.
  • Checks if the host is Connected or in Maintenance mode.
  • Retrieves the Encryption Recovery ID and Key.
  • Shows the current encryption mode.
  • Gracefully handles hosts that are offline or disconnected, clearly indicating skipped or problematic hosts.

Output

Connected hosts or in Maintenance with Encryption keys

Powered off or disconnected hosts – Skipped hosts

Hosts without encryption keys or with errors

Wrapping It Up

This quick script helps you stay on top of ESXi encryption keys effortlessly. Just copy, adjust if needed, and run. Happy scripting!

Veeam upgrade 12.2 to 12.3 step-by-step in pictures

Pre-upgrade checks

Stop & disable all backup jobs. And then stop all Veeam services.

You can use powershell to stop all Veeam* services:

Get-Service -Name "Veeam*" | Stop-Service

Mount installation ISO image and run “Setup.exe”

Choose what to upgrade

License Agreement

Upgrade

list of product which will be upgraded

License

If you have already licnesed Veeam, you will see your actual license. Otherwise you can browse local disk for license files or Sign in with Veeam.

Service Account

Database

Database upgrade

Configuration Check

Compatibility Issues

  • New Veeam Threat Hunter service -> https://www.veeam.com/kb1999
  • Selected location does not meet recommended disk space requirements -> extend disk where the Veeam is installed

You can find more details about upgrade in Veeam Help Center -> https://helpcenter.veeam.com/docs/backup/vsphere/upgrade_vbr.html?ver=120

Ready to Upgrade

Upgrade progress

Step 1 of 7:

Step 2 of 7:

Step 3 of 7:

Step 4 of 7:

Step 5 of 7:

Step 6 of 7:

Step 7 of 7:

Finish

Post upgrade

  • check that all services are UP.

Veeam Backup & Replication console which is installed on Veeam VBR server is upgraded automatically.

Components Update

Update

Component update completed

Re-enable previously disabled jobs.

And that’s all ๐Ÿ™‚