Assigning a substring of script output as a variable.

I am creating a menu within a batch script for users to run various scripts from. The point that I am stuck on is I need the Web Site ID from an IIS website (not the default website so it is not "1") for one of the scripts to execute.

I need to pass that Web Site ID to another script, I am hoping it is as easy as somehow setting the output of  [c:> cscript.exe %systemroot%\system32\iisweb.vbs /query "testsite"] to a temporary variable using "SET". and then using a substring function to grab the Web Site ID that was returned and putting it into the options for the other script. For instance: c:> otherscript.exe /F /P:%~websiteID,15,2% (or whatever)

If there is any easier way to get the Web Site ID of IIS website I am all ears but this was the only option I could think of. Thanks-Adam
LVL 2
adamhealyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
Actually after a google it looks like the output is like this

Products (W3SVC/1948497947) STARTED 172.30.163.244 80 N/A

So try this:

@echo off
for /f "tokens=2-3 delims=()/" %%a in ('cscript.exe %systemroot%\system32\iisweb.vbs /query "testsite"') do set output=%%b

otherscript.exe /f /p:%output%

to get the number only.  If it needs the w3svc bit too then

@echo off
for /f "tokens=2 delims=()" %%a in ('cscript.exe %systemroot%\system32\iisweb.vbs /query "testsite"') do set output=%%a

otherscript.exe /f /p:%output%
0
 
Steve KnightIT ConsultancyCommented:
You can use something like this (I don't have iisweb.vbs to test with):

@echo off
for /f %%a in ('cscript.exe %systemroot%\system32\iisweb.vbs /query "testsite"') do set output=%%a
set websiteid=%output:~15,2%
otherscript.exe /f /p:%websiteid%

Can you post the complete output you get from the iisweb.vbs command please.

thanks
Steve
0
 
adamhealyAuthor Commented:
dragon-it,
Thanks a bunch. Below is what I ended up using. Thanks again!, adam

@echo off
for /f "tokens=2 delims=()" %%a in ('cscript.exe %systemroot%\system32\iisweb.vbs /query "testsite"') do set output=%%a

ECHO %output:~6,9%

Which returned just the 123456789 number in the second column. Thanks.....
0
 
Steve KnightIT ConsultancyCommented:
No problem, I think the output of the command depends a bit on how teh system is setup but that will get you the bit in brackets anyway regardless of the rest of the line (as long as you don't use ( or ) in the name of the website!)

Don't for get to hit the "Accept answer" :-)
0
All Courses

From novice to tech pro — start learning today.