PowerCLI: Find BIOS-Enabled VMs

This script is an idea that spun off of my previous post, PowerCLI: Find UEFI-Enabled VMs. If you’re preparing to enable Secure Boot in a VMware environment, it may be helpful to identify the VMs that cannot be upgraded. As you might recall, enabling secure boot requires the following:

  • VMware vSphere 6.5 or higher
  • Virtual hardware version 13 or higher
  • VMs need to be configured with EFI boot firmware

Just like the Find UEFI script, I put this one together to scan a vCenter datacenter object for all VMs that have BIOS boot firmware configured. I’m also working on another variant of this script that will look up a single, specific VM to report if its boot firmware setting is set to UEFI or BIOS boot. Stay tuned for that script sometime soon. In the meantime, the Find BIOS-Enabled VMs script is below, but the latest version will be available over on GitHub.

############################################################
# Script: find-bios-vms-in-a-datacenter.ps1
# Author: Doug DeFrank
# Date: 2018-07-02
#
# Purpose: Find BIOS-enabled VMs in a specific VMware datacenter
############################################################

Write-Host `n "This script will find all BIOS-enabled VMs in a specific VMware datacenter." `n

### Define the date in the yyyyMMdd format
$date = Get-Date -format "yyyyMMdd"

### Prompt user for vCenter Server name, and connect to it
$vCenterServer = Read-Host -Prompt 'Enter the FQDN of the vCenter Server you want to connect to. (vcenter.domain.com)'
Connect-VIServer -Server $vCenterServer -WarningAction SilentlyContinue | Out-Null

### Choose a datacenter name
$DatacenterName = Get-Datacenter | Out-GridView -PassThru -Title "Select a Datacenter"

### Get all VMs in the chosen datacenter
$vms = $DatacenterName | Get-VM | Sort-Object

### Set the loop variable to 1
$loop = 1

$report = foreach ($vm in $vms) {
### Display a progress bar during VM checks
Write-Progress -Activity "Scanning for BIOS-enabled VMs..." -Status "Checking $vm" -PercentComplete ($loop/$vms.count * 100)

### If the VM boot firmware is set to BIOS, add it to the report
if ($vm.ExtensionData.Config.Firmware -eq "bios") {
$vm | Select-Object Name,@{N='Firmware';E={$_.ExtensionData.Config.Firmware}}
}
$loop++
}

### Check to see if the report is empty
if (!$report) {
Write-Host -ForegroundColor Red `n "No BIOS-enabled VMs found."
}

### If BIOS VMs are found, ask the user if they want to export the results to a CSV file
else {
Do {
Write-Host `n "Do you want to export the results to a CSV file?"
Write-Host "1.) Yes"
Write-Host "2.) No"
$csvexportyn = Read-Host
Switch ($csvexportyn) {

### If user chooses 1.) Yes, export to a CSV file in the same location as the script itself
1 {
Write-Host `n "Generating CSV > .\$DatacenterName-BIOS-VM-Report-$date.csv"
$report | Export-CSV -path ".\$DatacenterName-BIOS-VM-Report-$date.csv" -NoTypeInformation
$yn = $true
}

### If user chooses 2.) No, display a separate window with the scan results, and exit the script
2 {
$report | Out-GridView
$yn = $true
}

### Validate the user input. If it's not a 1 or a 2, repeat the question
default {
Write-Host -ForegroundColor Red -BackgroundColor Black ">>> Invalid input. Please enter a [1] for Yes or a [2] for No."
$yn = $false
}
}
}

### Loop through the "Export CSV" question until a valid choice is made
Until ($yn)
}

### Disconnect from the vCenter Server
Write-Host `n "Script Complete. Disconnecting from vCenter Server $vCenterServer."
Disconnect-VIServer -Server $vCenterServer -Confirm:$false | Out-Null

As always, thanks for stopping by! If you’ve found this post useful or helpful, let me know in the comments.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s