Public/Remove-P1WebApp.ps1

function Remove-P1WebApp {
    <#
    .Synopsis
    Uninstall a existing PlannerOne web application.
 
    .Description
    Uninstall a existing PlannerOne web application with the given parameters.
 
    .Parameter Tenant
    The tenant name of this web application.
 
    .Example
    # Uninstall a PlannerOne web application for the tenant Prod.
    Remove-P1WebApp -Tenant Prod
    #>

    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Tenant
    )
    Process
    {
        Write-Section "Removing web instance..." 
        $siteName = Get-SiteNameFromTenant $Tenant
        $poolName = Get-PoolNameFromTenant $Tenant
    
        $TenantInfo = Get-TenantInfo $Tenant
        if ($TenantInfo -ne $null) {
            $WebAppName = $TenantInfo.WebApplicationName
            Write-Verbose "Web application name read from tenant info is $WebAppName"
        }

        if (!$WebAppName) {
            Write-Verbose "No tenant info for web application name. Created one from convention"
            $WebAppName = Get-WebAppNameFromTenant $Tenant 
        }

        $sitePath = "$IISRootPath\$siteName"
        $webAppPath = "$sitePath\$WebAppName"

        # Remove WebApp
        Write-Verbose "Removing web app: $WebAppName"        
        Remove-WebApplication -Name $WebAppName -Site $siteName

        # Remove Site
        Write-Verbose "Removing site: $siteName"            
        Remove-WebSite -Name $siteName | Out-Null
        
        # Remove Pool
        Write-Verbose "Removing pool: $poolName"
        Stop-WebAppPool -Name $poolName
        Remove-WebAppPool -Name $poolName
        
        # Remove WebApp folder
        Write-Verbose "Removing folder: $webAppPath"
        Remove-Symlink $webAppPath

        # Remove Site folder
        Write-Verbose "Removing folder: $sitePath"
        Remove-Item $sitePath -recurse -Force
        Write-OK "Web instance removed"
    }
}