Automatically Create IIS Websites

2008-08-21 by Administrator, tagged as microsoft, programming

I had to create quite a lot websites on a Microsoft IIS webserver and of course there is a nice scripting solution to it. Here is how I did it:

Batch code:

@ECHO OFF
SET webRoot=D:\websites
ECHO.
ECHO Creating directories
ECHO and websites
ECHO.
FOR /F "eol=# delims=; tokens=1,2*" %%f in (websites.txt) DO (
	ECHO Creating Dir %webRoot%\%%f\%%g and website %%g in appPool %%h
	MD "%webRoot%\%%f\%%g"
	iisweb /create "%webRoot%\%%f\%%g" "%%g" /i 192.168.228.30 /d %%g.perimeterless.org /ap %%h
	ECHO.
)
pause

and here is the text file that goes with it:

#
# ";"-delimited file to create directory structure,
# websites and application pools
#
# Structure is
#
# Subdirectory	;	Sitename	;	AppPool
testing;test1;DefaultAppPool
testing;test2;DefaultAppPool
testing;test3;DefaultAppPool