Public/Remove-P1Tenant.ps1

function Remove-P1Tenant {
    <#
    .Synopsis
    Uninstall an existing PlannerOne tenant (service + web app).
 
    .Description
    Uninstall an existing PlannerOne tenant with the given parameters.
 
    .Parameter Tenant
    The tenant name.
 
    .Parameter RemoveData
    Remove all the data stored for this tenant.
 
    .Parameter WebAppName
    The web application name if customized.
 
    .Example
    # Uninstall a PlannerOne tenant named P1Prod.
    Remove-P1Tenant -Tenant P1Prod
    #>

    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Tenant,
        [switch] $RemoveData
    )
    Process
    {
        if (!(Test-Tenant $Tenant)) {
            Write-Warning "Tenant $Tenant does not exist."
            return
        }
    
        Write-Section "Removing tenant..."
        Remove-P1ServerInstance -Tenant $Tenant
        
        Remove-P1WebApp -Tenant $Tenant
        
        Remove-Tenant -Tenant $Tenant -RemoveData:$RemoveData.IsPresent
        Write-OK "Tenant '$Tenant' removed"
    }
}