skip to Main Content

Get disk free space with PowerShell

How to get disk capacity in GB, disk free space in GB, and disk free space in percentage with PowerShell? After we have the information, we like to copy it to a document. Do you want to have an output of the disk capacity and disk free space in percentage? You are on the right page. Let’s get into it and get the disk free space with PowerShell.

How to get disk free space with Disk Management

Start Disk Management. Have a look at the columns Capacity, Free Space, and % Free.

Get disk capacity and free space percentage with PowerShell disk management

What if you want to copy all the information to a document? Unfortunately, this is not possible from Disk Management. How can we make it possible? The solution to that is a PowerShell script.

Prepare get disk free space PowerShell script

Copy the below code and paste it in Notepad. Save the file type as Get-DiskSpace.ps1 in the C:\scripts\ folder. Create a scripts folder if you don’t have one on the C: drive. You can also download the Get-DiskSpace.ps1 script (direct link). If it does not give you a prompt to save the file, right-click on Get-DiskSpace.ps1 and click save link as. You should be able to save the script. The script in this article is my edit to the script from Mohammed Wasay.

Change line 5, $ServerName = ‘localhost’ to the machine’s name that you want to run the script against. For example, $ServerName = ‘DC01-2016’. If you want to get the disk space and free space of the machine you downloaded the script on, you don’t have to edit it.

Run get disk free space PowerShell script

After you have saved the Get-DiskSpace.ps1 script in the C:\scripts folder, you can run the script. Start PowerShell as administrator. Change the directory to the scripts folder and run the script.

The results are great. Total Capacity (GB) and Free Space (GB) is showing the result with two decimals. The list is sorted on available free space in percentage. Now that we have the information, we can copy the output and paste it in the document.

What if you want another decimal value? For example, one or three decimals showing as output. Change line 10 and line 17, n2 (two decimals) to n1 (one decimal) or n3 (three decimals).

Keep reading: Get mailbox database size and white space »

Conclusion

In this article, you learned how to get disk capacity and disk free space percentage with PowerShell. Download the Get-DiskSpace.ps1 script. Edit the name of the server in the script and run the script. Copy the output.

Did you enjoy this article? You may also like Connect to Exchange Online PowerShell using MFA. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Connect with ALI TAJRAN on social media. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top