Parsing the output of iisreset /status

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alexandredneto
Posts: 39
Joined: 28 Feb 2013 13:40

Parsing the output of iisreset /status

#1 Post by alexandredneto » 15 Jan 2014 11:55

Hello!

Command as shown below:
C:\>iisreset /status

Status for World Wide Web Publishing Service ( W3SVC ) : Stopped
Status for Simple Mail Transfer Protocol (SMTP) ( SMTPSVC ) : Stopped
Status for Windows Remote Management (WS-Management) ( WinRM ) : Stopped
Status for HTTP SSL ( HTTPFilter ) : Running

I'm trying to develop a code that has the status of values ​​in the variables below:
- W3SVC: Stopped
- SMTP: Stopped
- WinRM: Stopped
- HTTPFilter: Running

But I am not able to develop a code. Somebody help me with the code below:

Code: Select all

setlocal enabledelayedexpansion

set "cn="
set "status="
for /f "tokens=1,2 delims=:" %%f in ('IISRESET /STATUS') do (
   set "cn=%%f"&"status=%%g"
   if defined cn (
      set "W3SVC="
      set "SMTP="
      set "WinRM="
      set "HTTPFilter="
      for /f "delims=" %%k in ('echo !cn! ^| findstr W3SVC') do set "W3SVC=%%k"
      if defined W3SVC (
        set W3SVC=%status%
        )
      )
   )
echo W3SVC=%W3SVC%
echo SMTP=%SMTP%
echo WinRM=%WinRM%
echo HTTPFilter=%HTTPFilter%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: iisreset

#2 Post by foxidrive » 15 Jan 2014 21:21

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('iisreset /status') do (
 set "var=%%a"
 set "var=!var:*( =!"
   for /f "tokens=1,2 delims=): " %%b in ("!var!") do (
      set "%%b=%%c"
   )
)
pause


Post Reply