Servers: LIVE Monitoring

Following the topic of Monitoring services with Powershell and Monitoring disk drive space with Powershell, it is interesing to check servers continually:


I always like to call powershell scripts from batch scripts, and with a few more lines we can automate its execution every X minutes:

@echo off
set minutes=30
set /a seconds= 60 * %minutes% 
:home
powershell -noprofile .\CheckdiskdriveSpace.ps1

for /f "tokens=1,2,3 delims=:," %%a in ("%time%") do (set hh=%%a&set mm=%%b&set ss=%%c)
REM WORKING HOURS 8h-17h
if %hh% LEQ 17 (if %hh% GEQ 8 (echo Waiting %minutes% minutes... & sleep %seconds%) else (pause)) else (pause)
goto home
I split the %time% variable into hh:mm:ss and if hh is in the working hours i wait 30 minutes between executions, if  not, I pause the script until pressing any key.
We need SLEEP command to do so, it comes in Windows Resource Kit 2003.

Comments