Powershell retrieve Disk Usage Windows 10
Below is a simple PowerShell script that retrieves disk usage information for all drives on a Windows 10 system:
# Get disk usage for all drives
Get-PSDrive -PSProvider FileSystem | Select-Object Name, @{Name="Used (GB)";Expression={[math]::round(($_.Used/1GB),2)}}, @{Name="Free (GB)";Expression={[math]::round(($_.Free/1GB),2)}}, @{Name="Total (GB)";Expression={[math]::round(($_.Used + $_.Free)/1GB,2)}}
Explanation:
- Get-PSDrive: This cmdlet retrieves information about the drives on your system. The
-PSProvider FileSystem
parameter filters the results to show only file system drives. - Select-Object: This cmdlet is used to select specific properties to display. In this case, it selects the drive name, used space, free space, and total space, all converted to gigabytes (GB) for readability.
- [math]::round(): This method rounds the disk space values to two decimal places for easier reading.
Execute the Script:
- Open PowerShell on your Windows 10 device. You can do this by pressing
Win + X
and selecting “Windows PowerShell” or “Windows PowerShell (Admin)” if administrative privileges are needed. - Copy and paste the script into the PowerShell window.
- Press
Enter
to execute the script. It will display the disk usage information for all drives.
This script provides a quick and easy way to check disk usage without needing third-party tools. If you need to automate this task or run it on multiple machines, you can save the script in a .ps1
file and execute it as needed.