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
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
To get disk information at a logical level, run the command:
Get-Disk
Run the following command to display information about partitions on all disks:
Get-Partition
To find out information about volumes on all disks, run the command:
Get-Volume
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
As you can see in the screenshot above, the Size column is displayed in bytes.
When you run Get-Disk
, Get-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}}
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)}}
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
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)}}
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
To display section C information, run the command:
Get-Partition -DriveLetter C
And as an example for Get-Volume
cmdlet, display information about volume C, to do this, run the command:
Get-Volume -DriveLetter 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.