Disk Volume Serial Numbers

A question was asked in the newsgroup about getting the Volume Serial Number of a disk in PowerShell.

One answer is to use

Get-WmiObject Win32_volume | Format-table Name, @{Label = "SerialNumber"; Expression = {"{0:X}" -f $_.SerialNumber}}  -auto

Note the use of the calculated column in the Format-Table.  This is because Win32_Volume returns the serial number as a decimal integer rather than a hex number as dir in a cmd prompt does.  Win32_Volume is only available on Vista and above.

Alternatively try

Get-WmiObject Win32_logicaldisk | Format-table Name, volumeserialnumber

which will work on XP.  It returns the volume serial number as hex.

This raises a very important point regarding WMI.  It is an evolving technology and new classes seem to be added with each version of Windows.  It is important to check which versions of Windows support a particular class.

Technorati Tags: ,
This entry was posted in PowerShell and WMI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s