7

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!

Julian Dormon
  • 1,767
  • 4
  • 32
  • 58

3 Answers3

15

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
)
Eric Bonnot
  • 2,004
  • 1
  • 20
  • 22
  • This works for the top level node, but what about a site located under "Default Web Site"? – Paul Nov 04 '16 at 16:51
0

Here's the PowerShell way:

$exists = (&$appcmd list apppool /name:'MyApplicationPool') -ne $null

if ($exists -eq $false)
{
    Write-Host 'App Pool does not exist'
}
else
{
    Write-Host 'App Pool exists'
}
niaher
  • 9,460
  • 7
  • 67
  • 86
0

You can specify the site.name and do that in one line with the command line : "%systemroot%\system32\inetsrv\AppCmd.exe" list apps /path:"/PORTALSiteName" /site.name:"Default Web Site" && ECHO EXISTS

yannick
  • 137
  • 1
  • 12