Powershell offers quick ways to find disk usage on a computer. Rather than loading the management snap-in for disk administration, you can use a quick set of Powershell commands to find disk usage for each partition. We look at multiple ways by which you can use Powershell to find free disk space on the computer.
Here are the things that we will look into in this document:
- PSDrive command for disk partition information on local computer
- PSDrive command to look into used and free space on a particular partition, based on the drive letter
- a command to find used and free disk space for a remote computer
Disk usage using PSDrive Command in Powershell
PSDrive is the quickest method to find used and free space on a hard drive on a local computer. The command output will give complete volume information, including the drive letters for each partition and the used or free space on the disk.
In the search box on your Windows 11 computer, type pwsh to launch the Powershell session on your computer. Alternatively, you can launch a command prompt session and type pwsh to bring up a new Powershell session on any Windows computer.
Once you are in the Powershell environment, we will use the GetPSDrive command to find the volume information for hard drives connected to the local computer.
You can notice that the command output contains:
- volume information for each partition
- used disk space for each partition in GB
- free disk space for each partition in GB
If you prefer to find free and used disk space for a specific drive letter, you can use a single Powershell command for concise output.
To find used and free disk space for C: on your local computer, you can use the following Powershell command. The command output is shared as a display image below the command.
Get-PSDrive C | Select-Object @{ E={$_.Used/1GB}; L=’Used’ }, @{ E={$_.Free/1GB}; L=’Free’ }
For finding used and free space on disk partition D: you will need to modify the command to include the drive letter next to Get-PSDrive command as displayed below.
Get-PSDrive D | Select-Object @{ E={$_.Used/1GB}; L=’Used’ }, @{ E={$_.Free/1GB}; L=’Free’ }
Here is what the command output looks like when you give these two commands in the Powershell window:
The Get-PSDrive cmdlet is one of the most commonly used cmdlets for finding disk partition information for local computers.
Find free and used disk space on remote computers
For remote computers, you can connect to the computer remotely through a New-PSSession command. Once you are connected to the remote computer, you can use the Get-PSDrive cmdlet to find disk information. However, there is another alternative option to find free and used disk space on a remote or local computer.
The Powershell command below will find the disk information for D: for a remote computer whose name is ‘remotecomputername’. For your network, you can replace ‘remotecomputername’ with the actual computer name. The computer name could be the name for a local computer or a remote computer.
The command to find free and used space (in GB) for a remote computer is:
$disk = ([wmi]”\\remotecomputername\root\cimv2:Win32_logicalDisk.DeviceID=’D:'”)
“Remotecomputer D: has {0:#.0} GB free of {1:#.0} GB Total” -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output
You will need to replace the letter in cimv2:Win32_logicalDisk.DeviceID=’D: to the drive letter that corresponds to disk partition for which used and free disk space is needed. For example, if you wish to find free and used disk space for C: on a remote computer SYSTEM-02, we will use this command in the Powershell window:
$disk = ([wmi]”\\SYSTEM-02\root\cimv2:Win32_logicalDisk.DeviceID=’C:'”)
“Remotecomputer C: has {0:#.0} GB free of {1:#.0} GB Total” -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output
Through this command, we are creating a variable $disk that will contain the free and used disk space for a particular drive letter. In the next command, we are printing the variable to display the free and used disk space for a drive partition of the local or remote computer.
The command output below displays the disk usage on C: and D: through two separate commands:
You could use complicated Powershell scripts to automate disk space audits. For simple requirements, you could use the Get-PSDrive command and the WMI variable object to find free and used disk space on a local or remote computer.
Disk usage through Get-Volume command on Powershell
Another simple cmdlet to find disk volume information for local disks is the Get-Volume cmdlet. You can type the command Get-Volume to find high level disk volume information. The display shot below captures the command and its output in a Powershell window.
You may like to read more content related to Powershell tutorials below:
- How to find failed Windows Updates using Powershell?
- How to download a file from a URL using Powershell?
- How do I remove spaces in Powershell?
- How to force logoff a user in Powershell?
- How to find the DNS server address using Powershell?
- How to find event logs in the date range in Powershell?
- How to set the DNS server address using Powershell?
- How to empty recycle bin with Powershell?
Rajesh Dhawan is a technology professional who loves to write about Cyber-security events and stories, Cloud computing and Microsoft technologies. He loves to break complex problems into manageable chunks of meaningful information.