Take the 2-minute tour ×

This is what i am trying to do: I have a NLB Cluster. There are two machines on said cluster: Node1 and Node2. I have a third machine that is not in that, or any, cluster. This third machine is called: Monitor1

Once every hour, i would like to run a script to check if Node1 and Node2 are up. This script will be run via TaskScheduler. I am using the following command to execute the script on Node1 and Node2:

wmic /node:NODE1,NODE2 process call create "C:\ClusterCheck.bat"

The contents of the ClusterCheck.bat script is as follows:

NLB Query | findstr /i /R /C:"host . is stopped"
code here

When I use wmic /node:"%1" process call create "C:\ClusterCheck.bat" there is not output. When I go into the server and manually double click the ClusterCheck.bat file, it gives me the appropriate output depending whether the node is up or down.

Does anyone have any ideas how I can get those files to output?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

First problem, when you wmic process call create you should use prefix your command with cmd /c.

Next, you're right. wmic doesn't display the resulting output of the remotely created process on your local console. You'll either need to use psexec which was designed for this sort of thing, or hack a workaround by piping the command output to a log file then reading the log file. Something like the following script.

I'm not really clear, if this is going to be a scheduled task, why you're concerned with results being available to stdout. I suspect you intend to redirect the output to a log of some sort. So I put that in here as well.

@echo off

set "user=domainadmin"
set "pass=password"

for /f %%I in ('wmic os get localdatetime') do set "timestamp=%%I"
set "today=%timestamp:~0,8%"

set logfile=c:\users\me\Desktop\logs\%today%.log

if not exist "%logfile%" mkdir "%logfile%\.." 2>NUL
>>"%logfile%" echo %time%

for %%I in (NODE1 NODE2) do (
    (ping -n 1 %%I >NUL && (
        net use \\%%I /user:%user% %pass% >NUL 2>NUL
        wmic /node:%%I /user:%user% /password:%pass% process call create "cmd /c c:\clustercheck.bat >c:\cc.log"
        type \\%%I\c$\cc.log && del \\%%I\c$\cc.log
        net use \\%%I /delete >NUL 2>NUL
    ) || echo %%I unresponsive

forfiles /p "%logfile%\.." /M *.log  /d -30 /c "cmd /c del @path"

This should create Desktop\logs if it doesn't exist, then create or append to Desktop\logs\YYYYMMDD.log the output of C:\clustercheck.bat run on NODE1 and NODE2. Finally, it deletes log files that are over 30 days old.

share|improve this answer
Actually, now that I think about this, all the backslashes might need to be escaped with another backslash, like \\\\%COMPUTERNAME%\\etc. I'll have to test this in the morning. –  rojo Apr 18 '13 at 2:42
PSExec will not work properly with Task Scheduler. I have spent the better part of yesterday trying to make it work with no luck. –  gmilic Apr 18 '13 at 12:52
what is %CD::=$% supposed to mean? –  gmilic Apr 18 '13 at 12:52
%CD::=$% is the same as %CD% which is the current working directory. The stuff in the middle substitutes colons for dollar signs. So where "%CD%" == "C:\Users" you have "%CD::=$%" == "C$\Users". –  rojo Apr 18 '13 at 12:59
The above does not work. This is what i have typed in: wmic /node:<Node1> process call create "cmd /c C:\ClusterCheck.bat >> \\\\NetworkShare\\cc.log" >>type cc.log –  gmilic Apr 18 '13 at 13:08
show 4 more comments

Your Answer


