I try to create a virtual directory under the "Default Web Site" in IIS 7 using AppCmd. First I however like to see if one already exist. How can I use AppCmd to create a virtual directory under the "Deafult Web Site" and how can I do an if-statement?

link|improve this question
feedback

1 Answer

up vote 4 down vote accepted

Try this:

@ECHO OFF
REM --------------------------------------------------------------------------------
REM Check for and create VDir under Default Web Site
REM
REM %1 is the VDIR to create
REM %2 is the Physical path to the VDIR 
REM --------------------------------------------------------------------------------

IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax

ECHO Running...
ECHO   AppCmd.exe list vdir "Default Web Site/%1/"
ECHO.
AppCmd.exe list vdir "Default Web Site/%1/"
IF %errorlevel%==1 GOTO Exists

ECHO.
ECHO Running...
ECHO   AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2
ECHO.
AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2

GOTO End

:Exists
ECHO.
ECHO VDir already exists
ECHO.
GOTO End

:SYNTAX
ECHO.
ECHO VDir Name and Physical Path Required
ECHO.
ECHO CreateVDir.CMD ^<VDirName^> C:\PhysPath
ECHO.

:END
link|improve this answer
Cool! This is just what I need to get going! Thanks! Looks like ServerFault might be just as good as SO! – Riri Jul 29 '09 at 7:00
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.