I have been running the following script in the cmd file to get the free disk space of remote servers.It returns size in byte, is there any way to get the size in MB or GB, ideally percentage would be good.
echo off
echo .
echo SERVER-1:
wmic /NODE:"SERVER-1" logicaldisk get size,freespace,caption
echo .
echo .
echo .
echo SERVER-2:
wmic /NODE:"TSERVER-2" logicaldisk get size,freespace,caption
echo .
pause
I would recommend PowerShell rather than wmic
in cmd.exe
. Short example:
Get-WmiObject Win32_LogicalDisk -ComputerName server-1,server-2 -Filter "DriveType=3" | Select-Object `
@{Name = "ComputerName"; Expression = {$_.__SERVER}},
DeviceID,
@{Name = "Size"; Expression = {$_.Size / 1GB}},
@{Name = "Free"; Expression = {$_.FreeSpace / 1GB}}
This produces output such as the following:
ComputerName DeviceID Size Free
------------ -------- ---- ----
server-1 C: 99.5097618103027 64.3940238952637
server-1 D: 199.873043060303 183.510925292969
server-2 C: 99.5097618103027 64.3940238952637
server-2 D: 199.873043060303 183.510925292969
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.