Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

Get free disk space for mount points using Powershell

21 June,2021 by Tom Collins

Question: How can I get the capacity & freespace on Windows drives including mount points using Powershell. 

 

Answer: Win32_Volume class “represents an area of storage on a hard disk”.     Normally - we may look first at Win32_LogicalDisk class  “represents a data source that resolves to an actual local storage device on a computer system running Windows”.    

A volume mount point is a drive or volume in Windows that is mounted to a folder that uses the NTFS file system. A mounted drive is assigned a drive path instead of a drive letter. By using volume mount points, you can  mount, a target partition onto a folder on another physical disk.

--Get freespace and capacity of every drive & mountpoint on a Windows servers. This will return the figures as bytes

Get-WmiObject Win32_Volume | Format-Table Name, Label, FreeSpace, Capacity

--Get freespace and capacity of every drive & mountpoint on a Windows servers. This will return the figures as GB. 

--Added the Round function and limited to 2 decimal points 

Get-WmiObject Win32_Volume  | Select-Object driveletter,Label,@{Name='freespace';Expression={[math]::Round($_.freespace/1GB,2)}},@{Name='capacity';Expression={[math]::Round($_.capacity/1GB,2)}}

 

--Add the -computername switch if you need to check remotely 

Get-WmiObject Win32_Volume  -computername MYCOMPUTER| Select-Object driveletter,Label,@{Name='freespace';Expression={[math]::Round($_.freespace/1GB,2)}},@{Name='capacity';Expression={[math]::Round($_.capacity/1GB,2)}}

Read more on Powershell & disk management 

Powershell script to check disk space on remote servers

Powershell script function for disk free

How to master Mount-Diskimage in Powershell

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Get free disk space for mount points using Powershell


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer