Wednesday 1 April 2015

Use PowerShell to detect if a disk is an SSD

Update 2016-03-18: If you are on Windows 8 / Server 2012 or later, use the 'MediaType' attribute of the 'Get-PhysicalDisk' output. See the comments for more detail.

I was talking with some colleagues recently who were having trouble detecting if a disk was a Solid State Disk (SSD) or not in a lab environment. They wanted to run PowerShell scripts against the machines but found if the disk on the machine was a spindle disk it would cause an issue without a built-in delay. They wanted to detect if the disk was an SSD to remove the delay on machines that could handle it.

Easy I though. Just issue a Get-PhysicalDisk cmdlet and checkout the properties, no problem. Well that's what a PowerShell expert would think anyway. It turns out not to be the case.

After a lot of mucking about and searching I found there is no information reported from an ATA device to tell the operating system that it is an SSD. This makes sense I suppose seeing the concept of an SSD would have been unimaginable back when the interfaces were designed.

It turns out the best way to detect if an attached disk is an SSD or not is by reading two properties of the disk being, spindle speed (or rotation rate) and seek penalty. Neither of these properties are exposed by PowerShell or .NET.

Thanks to the Add-Type cmdlet and a guy from this blog (sorry, I can't find your name on the site), I created this PowerShell script to report if a disk is an SSD or not.

Simply copy the code to a script file and run it passing in a physical disk id number. It will return $true if the disk is an SSD, or $false if not. It will also return $false if exceptions occur in the Win32 DLL calls.


5 comments:

  1. I have very little experience in scripting but couldn't you use MSFT_PhysicalDisk class MediaTypeData type: UInt16 to identify 3 HDD or 4 SSD? https://msdn.microsoft.com/en-us/library/windows/desktop/hh830532(v=vs.85)

    ReplyDelete
    Replies
    1. Hi Bolsa. Yes, that looks like a lot better option than the script here. The TechNet article states Win8/2012 as minimum supported OS for this. I don't remember the details of why I was looking into this however maybe it was an older OS.

      `Get-PhysicalDisk | Select-Object DeviceId,MediaType`

      Perfect. Thanks heaps.

      Delete
    2. Excelente aporte, ¡el poder de lo sencillo! :)

      Comando para identificar desde PowerShell si el disco fisico es o no un SSD (Disco de Estado Sólido) Solid State Disk.

      Get-PhysicalDisk | Select-Object DeviceId,MediaType

      Gracias.

      Delete

    3. cheap windows and office product keys , windows anytime upgrade from starter to home basic key free , sql server 2008 r2 product key download , microsoft office groove 2007 product key 100% working , free windows product key , windows 8 key shop , buy server 2013 r2 keys , windows 10 activation t , lIMj07

      windows 7 ult key sale online

      buy office pro plus 2016 keys

      cheap windows 10 pro keys for sale

      windows server 2016 standard key sale and download

      buy windows 7 ult keys online

      Delete
  2. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. The difference:ssd vs hdd

    ReplyDelete