SQL SERVER – Powershell – Get a List of Fixed Hard Drive and Free Space on Server

Earlier I have written this article SQL SERVER – Get a List of Fixed Hard Drive and Free Space on Server. I recently received excellent comment by MVP Ravikanth. He demonstrated that how the same can be done using Powershell. It is very sweet and quick solution.

Here is the powershell script. Run the same in your powershell windows.

Get-WmiObject -Class Win32_LogicalDisk | Select -Property DeviceID, @{Name=’FreeSpaceMB’;Expression={$_.FreeSpace/1MB} } | Format-Table -AutoSize

Well, I ran this script in my powershell window, it gave me following result – very accurately and easily.

Get-WmiObject -Class Win32_LogicalDisk | Select -Property DeviceID, @{Name=’FreeSpaceMB’;Expression={$_.FreeSpace/1MB} } | Format-Table -AutoSize

SQL SERVER - Powershell - Get a List of Fixed Hard Drive and Free Space on Server pssize

Thanks Ravikanth one more time for excellent tip.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Powershell, SQL Scripts, SQL Stored Procedure
Previous Post
SQL SERVER – Get Directory Structure using Extended Stored Procedure xp_dirtree
Next Post
SQLAuthority News – SafePeak’s SQL Server Performance Contest – Winners

Related Posts

11 Comments. Leave new

  • Well sometimes you don’t have the access rights on some machine, while you have the rights to use xp_fixeddrives. I need both methods to get all the information I need.

    Reply
  • The source code for the PowerShell command is cut-off when viewed with IE9, so for those who cannot see the full line here it is:

    Get-WmiObject -Class Win32_LogicalDisk | Select -Property DeviceID, @{Name=’FreeSpaceMB’;Expression={$_.FreeSpace/1MB} } | Format-Table -AutoSize

    Reply
  • Good one, this is my first reply to sqlauthority.com. Pinal, it there any way to get total drive space as well?

    Reply
  • Can you also help the script to view the list of files which occupies more space in disk .

    Reply
  • a good one! simple and easy!

    Reply
  • Feodor Georgiev
    February 23, 2012 3:11 pm

    Here is a better script, which also displays mountpoints and status information:

    Reply
  • how do you add the computer name on the result

    Reply
  • This is exactly what I needed, but is there a way to display raid type i.e. Raid 0, etc?

    Reply
  • Is there a way to get Raid level information?

    Reply
  • Can i get the whole disk space with mount points using power shell and as well as i want all the servernames with physical names for all the servers.

    Reply
  • gwmi Win32_LogicalDisk -Filter “Drivetype=3” |select Computername, Name, FreeSpace,BlockSize,Size | % {$_.Computername=($env:COMPUTERNAME);$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_.FreeSpace=($_.FreeSpace/1GB);$_.Size=($_.Size/1GB);$_} | Format-Table Computername, Name, @{n=’Capacity_Gb’;e={‘{0:N3}’ -f $_.Size}}, @{n=’FreeGb’;e={‘{0:N2}’-f $_.FreeSpace}}, @{n=’Free_%’;e={‘{0:N2}’-f $_.BlockSize}} -AutoSize

    Computername Name Capacity_Gb FreeGb Free_%
    ———— —- ———– —— ——
    MyLaptop C: 465.760 397.52 85.35

    Reply

Leave a Reply