PowerShell 5.0

Get Hyper-V guest serial number with PowerShell

Learn how to retrieve the Hyper-V virtual machine’s serial number with PowerShell. Sometimes you need to have the serial number of a Hyper-V virtual machine (VM, or guest). We, for instance, use this serial number in our automatic, unattended deployment of the guest operating system. But then you need to know how to find this serial number…

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

Get-WmiObject
  -ComputerName hyper-v_server
  -Namespace root\virtualization\v2
  -class Msvm_VirtualSystemSettingData | select elementname, BIOSSerialNumberCode language: PowerShell (powershell)

if you want to use this PowerShell snippet as a command on the PowerShell command line, remove the backticks (`) and place the command on one line.

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-77Code language: PowerShell (powershell)

This PowerShell code utilizes the Get-WmiObject Cmdlet.

System administrators will likely rely heavily on Get-WmiObject to help them with their 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, InstanceIDCode language: PowerShell (powershell)

Jan Reilink

Hi, my name is Jan. I am not a hacker, coder, developer or guru. I am merely an application manager / systems administrator, doing my daily thing at Embrace - The Human Cloud. In the past I worked for clidn and Vevida. With over 20 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization. I blog at https://www.saotn.org.

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Anonymous
09/03/2017 23:51

Exactly what we needed, thank you sir!

RegEBarclay
18/08/2016 11:38

Very good job, sir. Thank you for sharing!