adamhealy
asked on
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\iisw eb.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
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\iisw
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\iisw eb.vbs /query "testsite"') do set output=%%a
ECHO %output:~6,9%
Which returned just the 123456789 number in the second column. Thanks.....
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\iisw
ECHO %output:~6,9%
Which returned just the 123456789 number in the second column. Thanks.....
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" :-)
Don't for get to hit the "Accept answer" :-)
@echo off
for /f %%a in ('cscript.exe %systemroot%\system32\iisw
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