How do I get the computer’s serial number? Consuming Windows Runtime classes in desktop apps, part 5: PowerShell

Raymond Chen

Raymond

Continuing our series on getting the computer’s serial number in desktop apps in various languages, we look at PowerShell.

I warned you that you’re going to be underwhelmed, so prepare to be underwhelmed.

# The following line has been broken up for readability purposes.
# Make sure to glue them together into one long line.
# (The continuation character doesn't work here.)
$addType = [Windows.System.Profile.SystemManufacturers.SmbiosInformation,
            Windows.System.Profile.SystemManufacturers,
            ContentType=WindowsRuntime]

[Windows.System.Profile.SystemManufacturers.SmbiosInformation]::SerialNumber

The first thing we do is add the type to PowerShell, which we do by loading up the type from the Windows Runtime metadata. Specify the type, the parent namespace, and say ContentType = WindowsRuntime.

And that’s it. We can now obtain the Serial­Number static property from the Smbios­Information class just like any other type.

Next time, we’ll wrap things up with a brief discussion of the Smbios­Information class itself.

Raymond Chen
Raymond Chen

Follow Raymond