Get Hyper-V guest serial number with PowerShell

Learn how to retrieve the Hyper-V virtual machine's serial number with PowerShell
Published on Sunday, 20 September 2015

PowerShell 5.0 logo

Sometimes you need to have the serial number of a Hyper-V hosts virtual machine (VM, or guest). You can use this serial number in your automatic, unattended deployment of the guest operating system. But well, you then need to know how to find this serial number...

The virtual machine's serial number, or BIOSSerialNumber, is an unique GUID with which you can identify a single running instance. Therefore having the Hyper-V guest serial number makes such a great source of documentation and information for automating your VM deployments across your network.

And that's where PowerShell comes in. The following PowerShell snippets print out all virtual machines on a Hyper-V server (host), with the Hyper-V serial numbers (a.k.a BIOSSerialNumber) for those VM's:

Get-WmiObject -ComputerName hyper-v_host -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | select elementname, BIOSSerialNumber

Or use Get-CimInstance:

Get-CimInstance -ComputerName hyper-v_host -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | select elementname, BIOSSerialNumber

The output is of the above Get-WmiObject command is:

elementname  BIOSSerialNumber
----------- ----------------
hyperv-vm-01 1111-2222-3333-4444-5555-6666-77
hyperv-vm-02 1112-2223-3334-4445-5556-6667-77

This PowerShell code utilizes the Get-WmiObject Cmdlet. Perfect for an automatic, unattended deployment of the guest and OS (set it as the InstanceID for example) and its documentation.

Nowadays you need to use Get-CimInstance. See Getting WMI objects with Get-CimInstance.

List all MAC addresses of all Hyper-V Virtual Machines

System administrators will likely rely heavily on Get-WmiObject to help them with your routine management tasks. Because at this time there are only a few cmdlets designed for carrying out system administration tasks (Get-Process, Get-Service, and Get-EventLog).

You can see Get-Service in action when monitoring Windows services with PowerShell.

The Hyper-V virtual machine's instance ID (GUID) is retrieved requesting InstanceID:

Get-WmiObject -ComputerName hyper-v_server -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | select elementname, InstanceID