script: creating an app pool, application and assigning the pool to the application

As usual, this one was harder than it should have been. Granted, this task is pretty easy through the UI, but I have a bunch of environments to manage that must be the sameā€¦ except for minor exceptions like the names of the site. Of course you have to supply the name of the site in these scripts. So what I did was find a way to output the name of the site based off the url of http://localhost and then set that to en environment variable that we use for the rest of the script.

You call this script with: scriptname vdirname path

******script******

set vdir=%1
set path=%2

echo %vdir%
echo %path%

%windir%system32inetsrvappcmd add apppool /name:%vdir%

FOR /F "tokens=*" %%i in (‘%windir%system32inetsrvappcmd list site http://localhost /text:site.name’) do SET IISSITENAME=%%i

%systemroot%system32inetsrvAPPCMD add app /site.name:%IISSITENAME% /path:/%vdir% /physicalPath:%path%

%systemroot%system32inetsrvAPPCMD set app "%IISSITENAME%/%vdir%" /applicationPool:%vdir%

******script******

Leave a Reply

Your email address will not be published. Required fields are marked *