January 10th, 2018

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

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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.