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

9 comments:

  1. Great script, Thanks for sharing..

    Vijay

    ReplyDelete
  2. wmic doesn`t work on XP Home

    ReplyDelete
  3. I got this error messagem when i ran the scripts above, please advise, thanks.

    Percy
    Error message :
    C:\TEST\diskspace>mon

    C:\TEST\diskspace>freespace DAL-TST-VIS-DB 1>>deskfree.txt

    C:\TEST\diskspace>mon
    Invalid Global Switch.
    Invalid Global Switch.

    C:\TEST\diskspace>freespace DAL-TST-VIS-DB 1>>deskfree.txt
    Invalid Global Switch.
    Invalid Global Switch.

    ReplyDelete
  4. @ppp888: I assume DAL-TST-VIS-DB is the hostname of the PC you would like to monitor.

    May I know if you are running this script with an account that has the local admin right for DAL-TST-VIS-DB?

    Moreover, what kind of version of XP you are running on DAL-TST-VIS-DB?

    Thanks.

    ReplyDelete
    Replies
    1. Yes. You need to have local admin right before you can run those script.

      The version is XP professional. I have not tried XP home.

      Delete
  5. Hi Fei,
    Hope you doing good.

    From my machine , i want to verify servers disk space.
    Everyday manually i am dng RDC to verify dispace.
    Do we have any automatica script , that will be helpful.

    For ex , abc is my system def is clients machine.... and how to modify above script and where to provide id & pwd of def machine etc.....
    It would be great help if you send your query.
    Thanks,
    Sai
    sai.gudiboina@gmail.com

    ReplyDelete
    Replies
    1. If you have active directory that hold all the server, you may use a domain account with local admin right to those server to run the script.

      If you do not have a domain, you probably have to use some 3rd party tools e.g. AutoIT script to store the username and password. There is no way to do that in command line for saving password.

      Delete
    2. You can however, use PowerShell script as well if your server have powershell installed. Powershell can save the password in the script.

      Delete
  6. Great script. It can be used also from Windows 7 without administrator privileges, just what i neeeded.

    Thanks.

    ReplyDelete