IIS: how to undeploy/delete/remove a webapp from c

2019-03-14 23:43发布

Suppose there's a webapp deployed on local IIS server. When I need to remove/undeploy it, I can go to IIS Manager, right-click on the app, and then select "Delete application and content" - et voila. But, I need to do the same from the command line - how? It can be assumed that the name of the application is known.

Maybe this can be done via MSDeploy somehow?

4条回答
Emotional °昔
2楼-- · 2019-03-15 00:24

I know the question says "command line", but you can use PowerShell and the IIS Administration Cmdlets to do this task. I provide all of the functions and explain the process of how to automate this on my blog. Also, you can easily swap out the IIS Administration Cmdlet calls with calls to msdeploy, appcmd, IIsVdir.vbs, etc.

For your specific question, this PowerShell code should do the trick:

$block = {
    Import-Module WebAdministration
    $website = "YourWebsiteName"
    $applicationName = "PathUnderWebsite\ToYourApplication"

    $fullPath = Join-Path $website $applicationName
    Write-Host "Checking if we need to remove '$fullPath'..."
    if (Get-WebApplication -Site "$website" -Name "$applicationName")
    {
        Write-Host "Removing '$fullPath'..."
        Remove-WebApplication -Site "$website" -Name "$applicationName"
    }

    Write-Host "Deleting the directory '$fullPath'..."
    Remove-Item -Path "IIS:\Sites\$fullPath" -Recurse -Force
}
$session = New-PSSession -ComputerName "Your.WebServer.HostName"
Invoke-Command -Session $session -ScriptBlock $block
Remove-PSSession -Session $session
查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-15 00:31

If you just want to remove the application from the Web Site in IIS without physically deleting the files (like msdeploy does) or if you don't have the WebDeploy-extension installed, you can use the following command:

C:\Windows\System32\inetsrv\appcmd.exe delete app "Default Web Site/MyAppName"
查看更多
劫难
4楼-- · 2019-03-15 00:33

iisweb /delete WebSite [/s Computer [/u [Domain ]User /p Password ]]

查看更多
女痞
5楼-- · 2019-03-15 00:34

This is what did it:

"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy" -verb:delete -dest:apphostconfig="Default Web Site/<webapp_name>"
查看更多
登录 后发表回答