Admin/Site/Remove-SDPSite.ps1

Function Remove-SDPSite
{
    <#
    .SYNOPSIS
        Delete Site by id
 
    .PARAMETER SiteId
        Site id
 
    .EXAMPLE
        $Status = Remove-SDPSite -SiteId 54321
 
    .NOTES
        Author: Michal Gajda
 
    .LINK
        https://ui.servicedeskplus.com/APIDocs3/index.html#delete-an-user
    #>

    [CmdletBinding(
        SupportsShouldProcess=$True,
        ConfirmImpact="Low"
    )]
    param (
        [String]$UriSDP,
        [String]$ApiKey,
        [Parameter(Mandatory=$true,
            ValueFromPipeline)]
        [Int]$SiteId
    )

    Begin
    {
        #Create headers
        if(!$MyInvocation.BoundParameters.ContainsKey("UriSDP"))
        {
            if($Global:UriSDP)
            {
                $UriSDP = $Global:UriSDP
            } else {
                Write-Error "UriSDP parameter is required or run Set-SDPApiConnection first." -ErrorAction Stop
            }
        }
        if(!$MyInvocation.BoundParameters.ContainsKey("ApiKey"))
        {
            if($Global:ApiKey)
            {
                $ApiKey = $Global:ApiKey
            } else {
                Write-Error "ApiKey parameter is required or run Set-SDPApiConnection first." -ErrorAction Stop
            }
        }
    }

    Process
    {
        $InvokeParams = @{
            UriSDP = $UriSDP
            ApiKey = $ApiKey
            Method = "DELETE"
            EntityUri = "/api/v3/sites/$SiteId"
        }

        #Send request
        If ($PSCmdlet.ShouldProcess($SiteId,"Delete site by id"))
        {
            $Result = Invoke-SDPAPIEntity @InvokeParams
            $Results = $Result.response_status
        }

        #Return result
        if($MyInvocation.BoundParameters.ContainsKey("Debug"))
        {
            Return $Result
        } else {
            Return $Results
        }
    }

    End{}
}