How to get the disk information using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To get the Windows disk information using PowerShell, we can use the WMI command or the CIM class command.

With the WMI command,

Gwmi Win32_LogicalDisk

With the CIM instance method,

Get−CimInstance Win32_LogicalDisk

You can see both the outputs are identical. Let’s use one of them.

DeviceID DriveType ProviderName VolumeName Size FreeSpace
-------- --------- ------------ ---------- ---- ---------
C: 3 53317988352 44027125760
D: 5 HRM_SSS_X64FREE_EN-US_DV5 3694962688 0
E: 3 Temporary Storage 10734268416 10238513152

Now there are different drive types associated with Windows and they each have an identical number. For example, Drive Type ‘3’ mentions the logical disk. The other types are as below.

2 = "Removable disk"

3="Fixed local disk"

4="Network disk"

5 = "Compact disk"

Here, we will filter only logical system disks. For that, we can use the below command.

Get−CimInstance Win32_LogicalDisk | where{$_.DriveType −eq '3'}

Output

DeviceID DriveType ProviderName VolumeName Size FreeSpace
-------- --------- ------------ ---------- ---- ---------
C: 3 53317988352 44027023360
E: 3 Temporary Storage 10734268416 10238513152

The above size is displayed in bytes. You can convert it to GB using an expression. Use the below command, to convert the Size and FreeSpace into GB.

Get−CimInstance Win32_LogicalDisk | where{$_.DriveType −eq '3'} `
| Select DeviceID, DriveType,VolumeName,
@{N='TotalSize(GB)';E={[Math]::Ceiling($_.Size/1GB)}}, @{N='FreeSize(GB)';E={[Math]::Ceiling($_.FreeSpace/1GB)}} |
ft −AutoSize

Output

DeviceID DriveType VolumeName TotalSize(GB) FreeSize(GB)
-------- --------- ---------- ------------- ------------
C: 3 50 42
E: 3 Temporary Storage 10 10
raja
Published on 25-Jan-2021 11:45:06
Advertisements