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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Steve KnightIT ConsultancyCommented:
Actually after a google it looks like the output is like this

Products (W3SVC/1948497947) STARTED 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%

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamhealyAuthor Commented:
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.....
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" :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.