Checking disk capacity in windows of remote servers

18

3

I am working in windows and I wanna to find out through command line disk capacity of remote windows servers.

For ex: I am @localhost, now I want to know whether D: drive of server 172.68.68.68 is greater 10 GB or not. How can I check?

All servers are running windows OS

rocko

Posted 2014-06-10T09:23:54.300

Reputation: 181

Answers

18

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"
    }

}

Keltari

Posted 2014-06-10T09:23:54.300

Reputation: 57 019

9

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"

Joachim Marder

Posted 2014-06-10T09:23:54.300

Reputation: 390

FYI, this will require administrative credentials. – Bink – 2019-10-29T15:53:08.753

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).

mtak

Posted 2014-06-10T09:23:54.300

Reputation: 11 805

1

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

LatinSuD

Posted 2014-06-10T09:23:54.300

Reputation: 1 194

0

Function GetRemoteDiskSpace (
[String]$TargetComputer,
[String]$Drive
)
{
$Drive = New-PSDrive -Name K -PSProvider FileSystem -Root "\\$TargetComputer\$Drive$" -Persist
$Info = Get-PSDrive $Drive 
$Free = $Info.Free /1GB
Remove-PSDrive -Name $drive -PSProvider FileSystem

return $Free
}

Ryan

Posted 2014-06-10T09:23:54.300

Reputation: 1

1Welcome to Super User! Your contribution is welcome, but can you provide an explanation of the above function? :) – bertieb – 2018-04-09T15:42:58.200

0

guys I also came with a solution using idea of fsutil and telnet:

<package>

  <job id="vbs">

  <script language="VBScript">

     set WshShell = WScript.CreateObject("WScript.Shell")
     WshShell.Run "telnet 182.56.32.23 -l work"
     WScript.Sleep 500
     WshShell.AppActivate "Telnet"
     WScript.Sleep 500
     WshShell.SendKeys "y"
     WshShell.SendKeys "~"      
     WScript.Sleep 500
     WshShell.SendKeys "helloworld"
     WScript.Sleep 500
     WshShell.SendKeys "~"  
     WScript.Sleep 500
     WshShell.SendKeys "C:\Users\work2\Desktop\diskcheck.bat"   
     WScript.Sleep 200
     WshShell.SendKeys "~"

  </script>

 </job>

</package>

diskcheck.bat :

fsutil volume diskfree C:
Output:
Total # of free bytes        : 17084395520
Total # of bytes             : 249145847808
Total # of avail free bytes  : 17084395520

rocko

Posted 2014-06-10T09:23:54.300

Reputation: 181

I have never seen anyone install a telnet server on Windows, even the builtin one. Especially, since telnet has long since been considered insecure. – Keltari – 2019-11-11T12:45:46.687

any improvements ? – rocko – 2014-06-16T04:25:04.777