|
Answer» Hi There,
I am unable to find a solution to get the free space available on the disk drives and mount volumes (in windows server). i am looking for a command or batch file where i can get output like this. Drive F: has several mount points. How do i get an output like this in MB. This a sample in KB
Name Capacity Free space PercentFree ---- -------- --------- ----------- C:\ 146777567232 101463191552 69.13 % E:\ 68713955328 67994939392 98.95 % Q:\ 1069253632 1061010432 99.23 % O:\ 68713955328 21001535488 30.56 % P:\ 68713955328 68644261888 99.90 % F:\ 68713955328 68644233216 99.90 % F:\D01\ 1642818691072 19775197184 1.20 % F:\RRep\ 68713955328 68644286464 99.90 % F:\D033\ 549761228800 21194547200 3.86 % F:\D02\ 1642818691072 36596097024 2.23 % F:\Bkup\ 1642818691072 1419910320128 86.43 % F:\D04\ 1095212449792 4592365568 0.42 % F:\T01\ 1095212449792 815251521536 74.44 % F:\TDB\ 1095212449792 56733552640 96.49 %
regards HelenThis should help you: http://stackoverflow.com/questions/2539262/how-to-find-the-percentage-of-free-space-for-mapped-drivesthanks very much Linux711Hi Linux711,
the solution found in the link does not solve the problem.
for /f "usebackq delims== tokens=2" %%X in (`wmic logicaldisk where "DeviceID='C:'" get FreeSpace /format:value`) do set FreeSpace=%%x for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='C:'" get Size /format:value`) do set Size=%%x set FreeMB=%FreeSpace:~0,-6% set SizeMB=%Size:~0,-6% set /a Percentage=100 * FreeMB / SizeMB echo C: is %Percentage% % free
it only gives me the space avaible on a disk and not on mounted volume. Also you got to pass each drive letter as an argument to the file
Any other help please?
thanks
HelenHey All,
I found out the command that helps me to get volume information
wmic Volume get Name, Capacity, FreeSpace
Can someone help me to format it neatly and get the size in GB and get the % free
thanks HelenDoes WMIC in that command report your mount points too? Is that an issue?
Batch math can only natively handle 2^31 - 1 so you will have to resort to WSH or Powershell for the math. Batch code does not support floating point arithmetic and numbers are limited to 32 bit PRECISION. An alternate solution would be VBScript.
Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk where drivetype <> 5")
WScript.Echo "Name Capacity Free Free %" For each objDisk in colDisks percentfree = (objdisk.Freespace / objdisk.Size) * 100 With objDisk WScript.Echo .DeviceId & " " & pad(FormatNumber(.Size/1073741824, 2)) & " " & pad(FormatNumber(.Freespace/1073741824, 2)) & " " & FormatNumber(percentfree, 2) End With Next
function pad(strText) strText = Space(10) + strText strText = Right(strText, 8) pad = strText end function
Save script with a VBS extension and run from the command line as: cscript //nologo scriptname.vbs
If you have access to Powershell, that would also be a good alternate solution. Hey foxidrive & sidewinder, Check out Judago's website for a work around on the batch math limitations. Judago.webs.comThanks Squashman. What a monster that batch file is! Quote from: Squashman on August 30, 2012, 07:56:21 PM Hey foxidrive & sidewinder, Check out Judago's website for a work around on the batch math limitations. Judago.webs.com
Impressive piece of work. This work around now tops Letterman's Top Ten Reasons To Switch To Powershell. This version has TRIVIAL changes but it handles drive arrays up to 99 TB.
Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk where drivetype <> 5")
WScript.Echo "Name Capacity Free Free %" For each objDisk in colDisks percentfree = (objdisk.Freespace / objdisk.Size) * 100 With objDisk WScript.Echo .DeviceId & " " & pad(FormatNumber(.Size/1073741824, 2)) & " " & pad(FormatNumber(.Freespace/1073741824, 2)) & " " & FormatNumber(percentfree, 2) End With Next
function pad(strText) strText = Space(10) + strText strText = Right(strText, 9) pad = strText end functionthanks All for the answers.
With wmic Volume i can get free space available on mount point's as well. But the issue now is ITERATING through a list of servers across my company's servers from my laptop.
I am trying to combine DOS command and SQL to achieve the result. That eliminates issues with DOS command
thanks Helen
|