Skip to content

Get-HyperVVMBIOS

Hyper-V: Audits Generation 1 virtual machine BIOS configuration

#Requires -Version 5.1
#Requires -Modules Hyper-V

[CmdletBinding()]
Param (
    [string]$ComputerName = "localhost",

    [PSCredential]$Credential,

    [Parameter(Mandatory = $true)]
    [string]$Name
)

Process {
    try {
        $params = @{
            'ComputerName' = $ComputerName
            'ErrorAction'  = 'Stop'
        }
        if ($Credential) { $params.Add('Credential', $Credential) }

        $vm = Get-VM @params | Where-Object { $_.Name -eq $Name -or $_.Id -eq $Name }

        if (-not $vm) {
            throw "Virtual machine '$Name' not found on '$ComputerName'."
        }

        if ($vm.Generation -ne 1) {
            throw "BIOS configuration is only supported on Generation 1 virtual machines. VM '$Name' is Generation $($vm.Generation)."
        }

        $bios = Get-VMBios -VM $vm -ErrorAction Stop
        
        $result = [PSCustomObject]@{
            VMName       = $vm.Name
            BootOrder    = $bios.StartupOrder
            NumLockEnabled = $bios.NumLockEnabled
            Generation   = $vm.Generation
            Timestamp    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the name of the Hyper-V host. Defaults to the local machine.

Specifies the credentials to use for the remote connection.

Specifies the name or ID of the virtual machine.

An interactive directory of PowerShell scripts.