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


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 /’) do SET IISSITENAME=%%i

%systemroot%system32inetsrvAPPCMD add app / /path:/%vdir% /physicalPath:%path%

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



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s