Showing posts with label wmic. Show all posts
Showing posts with label wmic. Show all posts

Wednesday, February 23, 2011

How to monitor free space of a group of desktop

If you have some special group of desktop shared by a team, you may have the similar issue as me that the hard disk space used up quickly simply because of the temp file (like the ost file of outlook).

I have written a script to monitor the freespace of a few machines...

First of all, I create a freespace.bat file like this

----start of freespace.bat-----



@echo off
for /f "usebackq delims== tokens=2" %%x in (`wmic /node:%1 logicaldisk where "DeviceID='C:'" get FreeSpace /format:value`) do (set  tx1234=%%x)


for /f "usebackq delims== tokens=2" %%x in (`wmic /node:%1 logicaldisk where "DeviceID='C:'" get Size /format:value`) do (set  txsi=%%x)


echo %1;%tx1234%;%txsi%


----end of freespace.bat-----


This script basically will poll the PC that you specified provide the freespace and the disksize of c-drive.

The usage is like this

freespace.bat <hostname>


If you have a list of machines, then, you can simply put their hostname into a text file, e.g. deskfree.txt and then use the following batch file to check their freespace and echo the results into a text file.

----start of mon.bat-------

@echo off
del /q deskfree.txt
for /f %%y in (desk.txt) Do freespace %%y >> deskfree.txt

------end of mon.bat--------