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

3

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!

Illampu answered 6/4, 2013 at 20:38 Comment(0)
B
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
)
Berni answered 4/12, 2013 at 14:6 Comment(1)
This works for the top level node, but what about a site located under "Default Web Site"?Classicize
S
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'
}
Sonora answered 22/12, 2015 at 7:57 Comment(0)
S
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

Shiau answered 16/11, 2018 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.