Checking disk capacity in windows of remote servers

Solution 1:

Using Powershell, you can use the following command:

Get-WmiObject -Class win32_logicalDisk -ComputerName server1, server2, server3, etc | Select-Object pscomputername, deviceid, freespace, size

Replace server1, server2, etc with the remote server names or IPs.

The output looks like this:

enter image description here

If you want, you can add | Export-Csv -Path .\drives.csv to the end of the script to output the file to a comma separated value (CSV) file for use with Excel. If you do, when you you open Excel you will need to format the drive size columns in Excel as numbers.

Just for giggles, I wrote this PowerShell script that will perform the task on all servers in Active Directory:

$ErrorActionPreference= 'silentlycontinue'

Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties * | Select-Object Name |

ForEach-Object {
    If (Test-Connection $_.Name -Count 1){
        Get-WmiObject -Class win32_logicalDisk -ComputerName $_.Name | 
        Select-Object pscomputername, deviceid, freespace, size
    }
    else {
        Write-host $_.Name " Connection Error"
    }

}

Solution 2:

Use the command fsutil:

fsutil volume diskfree C:
fsutil volume diskfree \\server\share

Output will be like:

Total # of free bytes        : 851127304192
Total # of bytes             : 2147480485888
Total # of avail free bytes  : 851127304192

To get only the line with the free bytes you may use:

fsutil volume diskfree C: | find /i "avail free"

Solution 3:

If you are in a domain, you would probably be able to do something with WMI (WMI example). If you are not in a domain, you can go two ways for remote monitoring:

  • Set up SNMP (excellent doc with guide) and write scripts to poll the SNMP daemon.
  • Use a monitoring product. I've used Opsview and Ninja in the past. Microsoft SCOM is also a good alternative (if you can afford the license fees).

Solution 4:

If you have access to the network share and you have Cygwin installed you can do this command:

# df -h //myserver/shareddrive Filesystem Size Used Avail Use% Mounted on - 25G 13G 12G 52% //myserver/shareddrive