Friday, July 18, 2008

Querying Disk Space on Remote Servers using Batch with WMIC

Time to check the disk free space in GB and percentage on a server volume...

WMIC(Windows Management Instrumentation Command-line) makes another appearance!

Thanks to Tipsmark for this syntax (Response number 17 in this post). I added the /node switch and some error handling / usage to have this batch file work on remote machines.

@ECHO OFF
IF "%~1"=="" goto help
IF "%~2"=="" goto help

@SETLOCAL ENABLEEXTENSIONS
@SETLOCAL ENABLEDELAYEDEXPANSION

@FOR /F "tokens=1-3" %%n IN ('"WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace | find /i "%2""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!

IF %TotalSpace% LSS 0 goto error

@ECHO Total space: %TotalSpace%GB
@ECHO Free space: %FreeSpace%GB
@ECHO Used space: %TotalUsed%GB
@ECHO Percent Used: %PercentUsed%%%
@ECHO Percent Free: %PercentFree%%%

@SET TotalSpace=
@SET FreeSpace=
@SET TotalUsed=
@SET PercentUsed=
@SET PercentFree=
goto end

:error
echo.
echo *** Invalid server or drive specified ***
echo.
goto help

:help
echo.
echo diskfree.cmd
echo.
echo Queries remote server for free disk space.
echo Specify a MACHINENAME and a drive letter to be queried
echo.
echo Example: diskfree.cmd MACHINENAME c:
echo.
goto end


:end


Here's an example of the script being run with a target computer named 'LARS', checking for free space on the [F:] volume:





If parameters are not passed or passed incorrectly(wrong drive letter) the script outputs the following or similar:

Thursday, June 05, 2008

Remotely Remove IIS via the Command Line Using PsExec and Sysocmgr.exe

IIS components can be manually removed the with the Add/Remove Programs>>Add/Remove Windows Components tool in Control Panel, or they can be uninstalled from the command line with a little script Kung-Fu. Several Windows components can be added/removed using this same technique by modifying the answer file.

Here's the syntax:

psexec \\TARGETMACHINENAME –u DOMAINNAME\%username% sysocmgr /i:%windir%\inf\sysoc.inf /u:"\\path\to\share\IIS_REMOVE-unattended.txt" /r /q
Here are the contents of the IIS_REMOVE-unattended.txt answer file - I've chosen to remove only 3 relevant components of IIS:
[Components]
iis_common = OFF
iis_www = OFF
iis_inetmgr = OFF

Here's what execution looks like:


Running
sysocmgr /?
from Start>>Run will display the available parameters for the tool.

Thursday, May 15, 2008

50.7 cents per GB - WD External 2.5" USB-Powered Drive - WDMLZ3200CN

The going rate for consumer storage is $0.20/GB or less you say? Why pay so much?



Ah, but that's in 3.5" internal SATA drives. Once you're able to fit 320GB(298GB as reported by Windows) in a coat pocket without needing an additional bulky power adapter to lug around, you'll see the instant appeal of such a device.

Make sure you get one with a carrying case - which is to say - you'll likely buy the Western Digital My Passport™ Elite™ from Costco.

Starting today there is $30 off coupon in the Costco mailer on a 2.5" external 320GB drive(298GB as reported by Windows OS) - I spent $151.12 including tax today for mine. Comes with a carrying case and an LED capacity gauge on the side that lights up to indicate remaining capacity - 320gb of portable goodness.

You can sometimes ask the Customer Service desk at the warehouse for coupons if you don't have the mailer.

Otherwise you'll pay right around $160.95 to purchase online from Costco.

The device comes formatted as FAT32, which doesn't support files larger tha 4GB(2 32−1 bytes to be more precise), so format it with NTFS - that'll work with the latest *NIX & Windows OSes.

Disclaimer: I like Costco quite a bit.