{"id":3790,"date":"2025-03-23T15:24:13","date_gmt":"2025-03-23T13:24:13","guid":{"rendered":"https:\/\/vpxd.dc5.cz\/?p=3790"},"modified":"2025-03-23T15:24:14","modified_gmt":"2025-03-23T13:24:14","slug":"how-to-quickly-check-backup-esxi-host-tpm-encryption-recovery-key-using-powercli","status":"publish","type":"post","link":"https:\/\/vpxd.dc5.cz\/index.php\/2025\/03\/23\/how-to-quickly-check-backup-esxi-host-tpm-encryption-recovery-key-using-powercli\/","title":{"rendered":"How to Quickly Check\/Backup ESXi Host TPM Encryption Recovery Key Using PowerCLI"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Managing encryption across multiple ESXi hosts can be a bit of a hassle. But don&#8217;t worry. I&#8217;ve got a simple PowerCLI script that&#8217;ll save you time and headaches by quickly retrieving encryption status and recovery keys from your VMware environment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"151\" src=\"https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-33.png\" alt=\"\" class=\"wp-image-3795\" style=\"width:630px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Do You Need This?<\/strong><\/h2>\n\n\n\n<p>Ensuring your ESXi hosts are correctly encrypted is essential for security. Regular checks help prevent surprises later, especially during troubleshooting or audits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started<\/h2>\n\n\n\n<p>First, make sure you&#8217;re connected to your vCenter:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connect-VIServer -Server<\/code><\/pre>\n\n\n\n<p>Replace with your vCenter IP or FQDN.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Script Breakdown<\/h2>\n\n\n\n<p>Here&#8217;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 <a href=\"https:\/\/github.com\/musil\/vSphere_scripts\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub repository<\/a>  and file <a href=\"https:\/\/github.com\/musil\/vSphere_scripts\/blob\/main\/vCenter\/tpm_recovery_key_backup.ps1\" target=\"_blank\" rel=\"noreferrer noopener\">tpm_recovery_key_backup.ps1<\/a>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Connect to your vCenter server (if not already connected)\n# Connect-VIServer -Server &lt;VCENTER_IP_OR_FQDN>\n\n$esxis  = get-vmhost | Sort-Object\n\nforeach ($esx in $esxis) {\n    $key= @()\n    $enc = @()\n    if ($esx.ConnectionState -ne \"Connected\" -and $esx.ConnectionState -ne \"Maintenance\") {\n        Write-Host \"\"\n        Write-Host \"================================================================================\" -ForegroundColor Yellow\n        Write-Host \"\ud83d\udeab SKIPPED HOST\" -ForegroundColor Yellow\n        Write-Host \"Host                : $($esx.Name)\" -ForegroundColor DarkYellow\n        Write-Host \"Reason              : Not powered on or disconnected.\" -ForegroundColor DarkYellow\n        Write-Host \"================================================================================\" -ForegroundColor Yellow\n        Write-Host \"\"\n        continue\n    }\n    $esxcli = Get-EsxCli -VMHost $esx -V2\n    try {\n        $key = $esxcli.system.settings.encryption.recovery.list.Invoke()\n        $enc =  $esxcli.system.settings.encryption.get.Invoke()\n\n        Write-Host \"================================================================================\" -ForegroundColor DarkCyan\n        Write-Host \"\ud83d\udd39 ESXi Host        : $($esx.Name)\" -ForegroundColor Cyan\n        Write-Host \"\ud83d\udd10 Recovery ID      : $($key.RecoveryID)\" -ForegroundColor Green\n        Write-Host \"\ud83d\udddd\ufe0f  Recovery Key     : $($key.Key)\" -ForegroundColor Yellow\n        Write-Host \"\ud83d\udd12 Encryption Mode  : $($enc.Mode)\" -ForegroundColor Magenta\n        Write-Host \"================================================================================\" -ForegroundColor DarkCyan\n        Write-Host \"\"\n    }\n    catch {\n        Write-Host \"\"\n        Write-Host \"================================================================================\" -ForegroundColor DarkGray\n        Write-Host \"\u274c ERROR for host    : $($esx.Name)\" -ForegroundColor Red\n        Write-Host \"\u26a0\ufe0f  Failed to get encryption key for $($esx.Name) .\"\n        Write-Host \"\ud83e\udde8 Error details     : $_\"\n        Write-Host \"================================================================================\" -ForegroundColor DarkGray\n        Write-Host \"\"\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">What the Script Does<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Connects to each ESXi host.<\/li>\n\n\n\n<li>Checks if the host is <strong>Connected<\/strong> or in <strong>Maintenance<\/strong> <strong>mode<\/strong>.<\/li>\n\n\n\n<li>Retrieves the Encryption Recovery ID and Key.<\/li>\n\n\n\n<li>Shows the current encryption mode.<\/li>\n\n\n\n<li>Gracefully handles hosts that are offline or disconnected, clearly indicating skipped or problematic hosts.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Connected hosts or in Maintenance with Encryption keys<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1088\" height=\"150\" src=\"https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-31.png\" alt=\"\" class=\"wp-image-3792\" srcset=\"https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-31.png 1088w, https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-31-800x110.png 800w, https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-31-768x106.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Powered off or disconnected hosts &#8211; Skipped hosts<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"110\" src=\"https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-30.png\" alt=\"\" class=\"wp-image-3791\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Hosts without encryption keys or with errors<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"127\" src=\"https:\/\/vpxd.dc5.cz\/wp-content\/uploads\/2025\/03\/image-32.png\" alt=\"\" class=\"wp-image-3793\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping It Up<\/h2>\n\n\n\n<p>This quick script helps you stay on top of ESXi encryption keys effortlessly. Just copy, adjust if needed, and run. Happy scripting!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing encryption across multiple ESXi hosts can be a bit of a hassle. But don&#8217;t worry. I&#8217;ve got a simple PowerCLI script that&#8217;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 &hellip; <a href=\"https:\/\/vpxd.dc5.cz\/index.php\/2025\/03\/23\/how-to-quickly-check-backup-esxi-host-tpm-encryption-recovery-key-using-powercli\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Quickly Check\/Backup ESXi Host TPM Encryption Recovery Key Using PowerCLI&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3795,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,39,35,10,8],"tags":[11,47,12,46,36,37,45,48,44],"class_list":["post-3790","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-esxi","category-powercli","category-vcenter","category-vmware","tag-backup","tag-encryption","tag-esxcli","tag-key","tag-powercli","tag-powershell","tag-recovery","tag-script","tag-tpm"],"_links":{"self":[{"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/posts\/3790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/comments?post=3790"}],"version-history":[{"count":2,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/posts\/3790\/revisions"}],"predecessor-version":[{"id":3796,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/posts\/3790\/revisions\/3796"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/media\/3795"}],"wp:attachment":[{"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/media?parent=3790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/categories?post=3790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpxd.dc5.cz\/index.php\/wp-json\/wp\/v2\/tags?post=3790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}