Live Demo: 100% Patching Coverage in Just 5 Minutes

Wednesday January 8 | 12 PM EST / 9 AM PST and 11 AM CET / 10 AM GMT

Action1 5 How-to Articles 5 How to Get a PC Hard Drive Information with Powershell

How to Get a PC Hard Drive Information with Powershell

March 20, 2020

By Peter Barnett

This article describes a way to get hard drive and partitions information using Windows PowerShell.

In Windows operating systems there are various ways to obtain information about disks and partitions, for example, you can use the Disk Management utility with a graphical interface or the command-line utility diskpart.

Get Disk Drives Name, Model, Interface Type, Size and Serial Number Using Powershell

You can get hard drive and partitions information using the Powershell cmdlets of the Storage module. A list of all cmdlets of the Storage module can be obtained by running the Windows PowerShell console and running the command:

Get-Command -Module Storage

Get hard drive information powershell. Show list of all cmdlets Storage module

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

  • Get-PhysicalDisk allows you to get information about physical disks, device characteristics.
  • Get-Disk display disk information at the logical level of the operating system.
  • Get-Partition show partition information on all drives.
  • Get-Volume display volume information on all disks.

So, to get information about physical disks, start the command:

Get-PhysicalDisk

Get information about physical disks

To get disk information at a logical level, run the command:

Get-Disk

Get hard drive information powershell. Get disk information at a logical level

Run the following command to display information about partitions on all disks:

Get-Partition

find out information about partitions on all disks

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

Get-Volume

Get hard drive information powershell. Find out information about volumes on all disks

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

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

For example, display the device number, model, drive type, bus type, and size, to do this, run the command:

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

display the device number, model, drive type, bus type, and size

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

When you run Get-DiskGet-PhysicalDisk cmdlets without parameters, the Total Size column and the size in gigabytes are displayed, but if you run cmdlets with parameters, the property list contains the 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}}

Get hard drive information powershell. Display the size in gigabytes

Also, the size value can be rounded to the nearest integer using the data type [int], the command will look like this:

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

size value rounded to the nearest integer

You can also apply Format-Table to Get-Disk cmdlet, for example, display the number, name, size, and disk layout style, to do this, run the command:

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

Get hard drive information powershell. Apply Format-Table to Get-Disk cmdlet

Here the Size column also displays the size in bytes but using division as in the example above, you can get the size in gigabytes, to do this, run the command:

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

Size column displays the size in bytes

Let’s look at examples for Get-Partition cmdlet, for example, display all sections of disk 0, for this, run the command:

Get-Partition -DiskNumber 0

Get hard drive information powershell. Display all sections of disk 0

To display section C information, run the command:

Get-Partition -DriveLetter C

Get hard drive information powershell. Display section C information

And as an example for Get-Volume cmdlet, display information about volume C, to do this, run the command:

Get-Volume -DriveLetter C

display information about volume C

Consider Using Action1 to Show Disk Drives if:

  • You need to perform an action on multiple computers simultaneously.
  • You have remote employees with computers not connected to your corporate network.

Action1 is a solution for cloud patch management, software deployment, remote desktop, IT asset inventory, and endpoint management.

See What You Can Do with Action1

 

Join our weekly LIVE demo “Patch Management That Just Works with Action1” to learn more

about Action1 features and use cases for your IT needs.

 

spiceworks logo
getapp logo review
software advice review
trustradius
g2 review
spiceworks logo

Related Posts