#Howto fetch Disk space report using Powershell

disk space report using powershell

Fetch Disk space report using Powershell

Recently, I got a task to create disk utilization (Free space available in Percentage) report of 10-15 Windows 2008 Server. Disk utilization report is common in many projects where the techs have to prepare report and send it to the senior admins. Preparing such report is really a headache as you have to login to the server & check the utilization etc. which is a time consuming process. For our project I found that it takes near about 20-30 minutes to login and check the disk usage in all servers (the time will increase with increase in server count and vice versa). In this scenario PowerShell came to rescue us. In this post I am going to explain how to check disk space report using powershell

What is Powershell?

Windows PowerShell is a task automation and configuration management framework from Microsoft. In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), which are specialized .NET classes implementing a particular operation. Sets of cmdlets may be combined into scripts, executables (which are standalone applications), or by instantiating regular .NET classes (or WMI/COM Objects).These work by accessing data in different data stores, like the file system or registry, which are made available to the PowerShell runtime via Windows PowerShell providers.

Powershell for Calculating Disk Utilization

To calculate the Disk Utilization, we are going to use “win32_logicaldisk” class of the Powershell management cmdlet “Get-WmiObject”.

1) Open powershell windows in elevated mode

disk space report using powershell

2) Execute the below command to get the list of all the partitions, volume name, size, free space etc.

Get-WmiObject win32_logicaldisk -computer <computer-name>

disk space report using powershell

3) Now using the “select-object” tell powershell to show the value of objects DeviceID, VolumeName, Size and FreeSpace

Get-WmiObject win32_logicaldisk -computer <computer-name> | select-object DeviceID, VolumeName,Size,FreeSpace


4) Next step is to see the percentage free space. Using @{Name=””,Expression={}}:

Get-WmiObject win32_logicaldisk -computer <computername> |select-object DeviceID, VolumeName,@{Name=”PCTFreeSpace”;Expression={$_.FreeSpace/$_.Size*100}}


Powershell to fetch Disk information from Remote Servers

To fetch the Free space percentage of remote servers, you will just have to add those computers in the above command. So the command will be

Get-WmiObject win32_logicaldisk -computer <computername 1>, <computername 2>, <computername 3>, <computername N> |select-object DeviceID, VolumeName,@{Name=”PCTFreeSpace”;Expression={$_.FreeSpace/$_.Size*100}}


You can see in the above screenshot that Free space (in Percentage) of the servers is listed.

Online Resource to learn Powershell

Check “Microsoft Virtual Academy [MVA]” Jumpstart training to learn basics of Powershell scripting “Getting Started with Powershell 3.0”. The training is conducted by “Jeffery Snover” (Inventor of PowerShell).

About: Mike

Milind Koyande loves to work on new technologies specially virtualization and troubleshoot server problems. I’m an avid photographer and love to spend my free time close to nature, trying to capture its glory on my camera.

This site uses Akismet to reduce spam. Learn how your comment data is processed.