On occasion, I’ve need to fetch the BIOS serial number for Hyper-V guest machines BEFORE they’re powered-on.  Anyhow, here’s *a* way to fetch the serial numbers for all guests, or one guest in particular, from the Hyper-V host using PowerShell.

param (
  [parameter(Mandatory=$True)] [string] $HypervHost,
  [parameter(Mandatory=$False)] [string] $GuestName = ""
)
if ($GuestName -ne "") {
  Get-WmiObject -ComputerName $HypervHost `
    -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | 
      ? {$_.elementName -eq $GuestName} |
        Select -ExpandProperty BIOSSerialNumber
}
else {
  Get-WmiObject -ComputerName $HypervHost `
    -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | 
    ? {$_.BIOSSerialNumber -ne $null} |
      Select elementname, BIOSSerialNumber |
        Sort-Object elementName
}
Advertisements

One thought on “Get Hyper-V Guest BIOS Serial Numbers

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s