Public/Remove-P1ServerInstance.ps1

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

    [cmdletbinding()]
    param( 
    [Parameter(Mandatory=$true)]
        [string] $Tenant
    )
    Process
    {
    Write-Section "Removing server instance..."
        $serviceName = Get-ServiceNameFromTenant $Tenant
        $servicePath = Get-ServicePath

        #Test if service exists
        if (Test-ServiceExists($ServiceName)) {
            Stop-Service -Name $ServiceName -Force
            Write-Verbose "Deleting PlannerOne service for Tenant $Tenant"

            Remove-Service($ServiceName) | Out-Null
            # Remove Service folder
            Write-Verbose "Removing folder: $servicePath\$Tenant"
            Remove-Symlink "$servicePath\$Tenant"               
        Write-OK "Server instance removed"
        } else {
            # Always try to remove symlink
            Remove-Symlink "$servicePath\$Tenant"               
            Write-Warning "Service $ServiceName doesn't exist!"
        }     
    }
}