How to determine disk type with PowerShell & Get-PhysicalDisk

Black and White PDQ logo
Kris Powell|March 8, 2017
Determining Disk Type with Get-PhysicalDisk
Determining Disk Type with Get-PhysicalDisk

After today, you are going to know that determining disk type with Get-PhysicalDisk is super easy.

If you recently watched our PDQ & A webcast, you may have seen that we were unable to answer a question about how to determine if a disk is a solid state drive (SSD) or not.

Fast forward to now and we have that answer by utilizing Get-PhysicalDisk cmdlet.

Thanks PowerShell!

Gathering Physical Disk Information with Get-PhysicalDisk

If you’re using Windows 8 or later, you can get all the information you could ever want to know about your physical disk but were afraid to ask by running this (very) simple command:

Get-PhysicalDisk | Select *
Windows PowerShell script

Determining Disk Type with Get-PhysicalDisk

Armed with this new knowledge, of how to use Get-PhysicalDisk, let’s find out which (if any) of my physical disks are SSD.

Get-PhysicalDisk | Select FriendlyName, MediaType
Blog-SSD-or-not-Get-PhysicalDisk-example

Ta da!  Like magic, you can now determine your disk types!  That is, only if you’re using Windows 8 or higher. Should you happen to be stuck on older versions of windows, then you’ll just have to pretend to follow and/or sing along.

By default, just running Get-PhysicalDisk will not get you the MediaType, so be sure to select it specifically.

That’s it. We’re done. You can go home now and show off your new and powerful knowledge to your friends and neighbors.

There’s nothing more to see here. That is, unless you want to learn more! *gasp!*

Slightly Deeper Dive

Since it’s not a true deep dive, perhaps we should call this the casual saunter into the the shallow end of the pool of knowledge. If you’re still reading this far, we’ll show you the class that Get-PhysicalDisk appears to be using to gather those fancy properties.

In addition to the Get-PhysicalDisk cmdlet, we found that the MSFT_PhysicalDisk appears to provide exactly what we’re looking for. Knowing the class, here is how you would query that information with PowerShell.

Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage | Select FriendlyName, MediaType
Blog-SSD-or-not-MSFT PhysicalDisk-example

Unsurprisingly, this looks very similar to the result we got with Get-PhysicalDisk. Now, we just need to know what the media types 3 and 4 actually mean.

Based on this page about the MSFT_PhysicalDisk class (link here – Look for MediaType section), we can see which media types are available and what their values mean.

3 = HDD
4 = SSD

Since we know what these values now mean, we can modify our PowerShell above to use some calculated properties (fancy!) and include a simple switch statement to display friendlier results. Joy!

Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage | Select FriendlyName, SerialNumber, @{ name="MediaType"; expression={ switch ($_.MediaType) { 3 {"HDD"} 4 {"SSD"} } } }
Blog-SSD-or-not-MSFT PhysicalDisk-example-with-calculated-properties

Running the code above will show each physical disk and the associated media type. Amazing!

Alternatively, you could break this into multiple commands instead of the single command. But, that would have robbed me of the opportunity to use calculated properties.

Wrapping up

Like I mentioned before, I recommend that you use the first example since it’s much easier to remember and use:

Get-PhysicalDisk | Select FriendlyName, MediaType

As Always, go forth and PowerShell!

Black and White PDQ logo
Kris Powell

Kris was an employee at PDQ.

Related articles