How to use AppCMD to test and see if a website exists in IIS7 using the Site's Name?

Julian Dormon picture Julian Dormon · Apr 6, 2013 · Viewed 7.8k times · Source

I would like to add new bindings to a site using appcmd but I need to see if it exists first. How can I do so using AppCMD?

Much appreciated!

Answer

Eric Bonnot picture Eric Bonnot · Dec 4, 2013

You can create a batch file with the following code :

@ECHO OFF

SET appcmd=CALL %WINDIR%\system32\inetsrv\appcmd

%appcmd% list site /name:"Default Web Site"
IF "%ERRORLEVEL%" EQU "0" (
    ECHO EXISTS
    REM Add your bindings here
) ELSE (
    ECHO NOT EXISTS
)