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( 
        [string] $Tenant
    )
    Process
    {
    Write-Section "Removing web instance..." 
        $siteName = Get-SiteNameFromTenant $Tenant
        $poolName = Get-PoolNameFromTenant $Tenant
        $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"
    }
}