How to get hard drive information using Windows PowerShell

Information

The presented material is useful for all personal computer users and is informative and educational in nature.

In Windows, there are various ways to get information about disks and partitions, for example you can use the Disk Management GUI utility or the command line utility diskpart.

You can get information about disks and partitions using the Storage module commandlets. You can get a list of all the Storage module commandlets by running the Windows PowerShell console and running the command:

Get-Command -Module Storage

The main commandlets with which you can find out general information about disks and partitions:

  • Get-PhysicalDisk provides information about physical disks, device characteristics.
  • Get-Disk displays information about disks at the logical level of the operating system.
  • Get-Partition displays information about partitions on all disks.
  • Get-Volume displays information about volumes on all disks.

So let’s begin, to get information about the physical disks, run the command:

Get-PhysicalDisk

To get information about disks on the logical level, run the command:

Get-Disk

To find out partition information on all disks, run the command:

Get-Partition

To find out information about the volumes on all disks, run the command:

Get-Volume

Next, consider how to improve the information obtained in terms of visual perception. To do this, you can remove unnecessary information and add the necessary information, such as drive type and disk partitioning, as well as change the width of the table columns.

To do this, use the Format-Table commandlet to display the desired properties in the table, aligning the columns to the width of the content.

For example, let’s display the device number, model, drive type, bus type and size by running the command:

Get-PhysicalDisk | ft -AutoSize DeviceId,Model,MediaType,BusType,Size

As you can see in the screenshot above, the Size column is displayed in bytes.

When you run the Get-Disk, Get-PhysicalDisk commands without parameters, the Total Size column is displayed and the size in gigabytes, but if you run the commands with parameters, the properties list has only Size in bytes.

To display the size in gigabytes, run the command:

Get-PhysicalDisk | ft -AutoSize DeviceId,Model,@{Name=”Size, Gb”; Expression={$_.Size/1Gb}}

It is also possible to round the size value to an integer using the [int] data type, the command will look like this

Get-PhysicalDisk | ft -AutoSize DeviceId,Model,@{Name=”Size, Gb”; Expression={[int]($_.Size/1GB)}}

You can also apply the Format-Table to the Get-Disk commandlet, for example, to display the number, name, size, and style of the disk partitioning by running the command:

Get-Disk | Format-Table -AutoSize Number,FriendlyName,Size,PartitionStyle

Here too, the Size column shows the size in bytes, but applying the division as in the example above, you can get the size in gigabytes by running the command:

Get-Disk | Format-Table -AutoSize Number,FriendlyName,@{Name=”Size, Gb”; Expression={[int]($_.Size/1GB)}}

Let’s also look at examples for the Get-Partition commandlet, for example to display all partitions on disk 0,
to do this, run the command:

Get-Partition -DiskNumber 0

To display information about the C partition, run the command:

Get-Partition -DriveLetter C

And as an example for the Get-Volume commandlet, let’s display the information about volume C by running the command:

Get-Volume -DriveLetter C

You can find more information about the disk commandlets at docs.microsoft.com and technet.microsoft.com, or use the built-in Windows PowerShell help.

Rate article
Windows 10, Microsoft news, device reviews, registry and tweaks
Add a comment