IIS: how to undeploy/delete/remove a webapp from command line?

前端 未结 4 1673
暗喜
暗喜 2021-02-05 11:22

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

相关标签:
4条回答
  • 2021-02-05 11:53

    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
    
    0 讨论(0)
  • 2021-02-05 11:55

    This is what did it:

    "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy" -verb:delete -dest:apphostconfig="Default Web Site/<webapp_name>"
    
    0 讨论(0)
  • 2021-02-05 12:09

    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"
    
    0 讨论(0)
  • 2021-02-05 12:09

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

    0 讨论(0)
提交回复
热议问题