The Get-Disk
cmdlet in PowerShell gets all disks visible to the operating system. It returns physical disk objects like basic disks and partitioned drive partitions.
Get-Disk
There are various Powershell commands such as Get-Disk, Get-PhysicalDisk, Get-Partition, Get-Volume, and Get-CimInsance can be used to get details about disks.
In this article, we will discuss how to get disk details using PowerShell commands.
Get Disk Information using the Get-Disk cmdlet
To get disk information at the logical level of the Windows operating system, use the Get-Disk cmdlet in Powershell.
Get-Disk
The above PowerShell cmdlet returns the list of disks and their information such as Number, Friendly Name, Serial Number, HealthStatus, OperationalStatus, Total Size, and Partition Style.
PS C:\> Get-Disk
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
Style
------ ------------- ------------- ------------ ----------------- ---------- ----------
0 INTEL SSDS... BTLA624245EC515K Healthy Online 476.94 GB GPT
PS C:\>
Get Hard Drive Information using the Get-PhysicalDisk
Use the Get-PhysicalDisk cmdlet in PowerShell to retrieve the disk information about physical disks and device properties.
Get-PhysicalDisk
The above PowerShell script uses the Get-PhysicalDisk command to display the disk information.
PS C:\> Get-PhysicalDisk
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
Style
------ ------------- ------------- ------------ ----------------- ---------- ----------
0 INTEL SSDS... BTLA624245EC515K Healthy Online 476.94 GB GPT
PS C:\>
Display Partition Information of Drives using Get-Partition
You can use the Get-Partition cmdlet in PowerShell to display the partition information of all drives.
Get-Partition
The output of the above PowerShell command Get-Partition is:
PS C:\> Get-Partition
DiskPath: \\?\scsi#disk&ven_intel&prod_ssdsckkf5....
PartitionNumber DriveLetter Offset Size Type
--------------- ----------- ------ ---- ----
1 1048576 499 MB System
2 524288000 128 MB Reserved
3 C 658505728 189.9 GB Basic
4 204557254656 648 MB Recovery
5 D 205237780480 282.94 GB Basic
PS C:\>
Show Volume Information for All Disks using Get-Volume
You can use the Get-Volume cmdlet in PowerShell to display volume information for all disks.
Get-Volume
The above PowerShell Get-Volume command returns the list of all drives with information such as Drive Letter, Friendly Name, FileSystemType, DriveType, HealthStatus, OperationStatus, SizeRemaining, and free disk space.
The output of the above Get-Volume
to display disk information is:
PS C:\> Get-Volume
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
C Windows NTFS Fixed Healthy OK 13.25 GB 189.9 GB
NTFS Fixed Healthy OK 84.37 MB 648 MB
BOOT FAT32 Fixed Healthy OK 466.63 MB 495 MB
D Local Disk NTFS Fixed Healthy OK 44.93 GB 282.94 GB
PS C:\>
Get Disk Information Using WMI or CIM Class
You can use the WMI command or CIM class to get the Windows disk information using PowerShell.
# Using the WMI Command Gwmi Win32_LogicalDisk
The above PowerShell WMI command gets the Windows disk details.
The output of the above command is:
PS C:\> Gwmi Win32_LogicalDisk
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 14228705280
Size : 203898273792
VolumeName : Windows
DeviceID : D:
DriveType : 3
ProviderName :
FreeSpace : 48243216384
Size : 303799726080
VolumeName : Local Disk
PS C:\>
You can use the CIM class to get the disk details.
Get−CimInstance Win32_LogicalDisk
The above PowerShell command Get-CimInstance
uses the class Win32_LogicalDisk
to retrieve the Windows disk information. The output of the above command is:
PS C:\> Get-CimInstance Win32_LogicalDisk
DeviceID DriveType ProviderName VolumeName Size FreeSpace
-------- --------- ------------ ---------- ---- ---------
C: 3 Windows 203898273792 14227492864
D: 3 Local Disk 303799726080 48243216384
PS C:\>
Conclusion
I hope the above article on how to get disk information using PowerShell commands such as Get-Disk, Get-PhysicalDisk, Get-Volume, and CIM class is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.