PSSpamTitan.psm1

#Region '.\_PrefixCode.ps1' 0
# Code in here will be prepended to top of the psm1-file.
#EndRegion '.\_PrefixCode.ps1' 2
#Region '.\Classes\Get-CountryIso.ps1' 0
Class CountryIsos : System.Management.Automation.IValidateSetValuesGenerator {
    [string[]] GetValidValues() {
        Try {
            $scripts = Invoke-RestMethod -Uri https://api.first.org/data/v1/countries -Method Get -ErrorAction Stop
            $CountryIsos = ForEach ($script in $scripts.Data) {
                $script.psobject.properties.name
            }
        }
        catch {
            throw "Failed to retieve Country ISO codes from 'https://api.first.org/data/v1/countries'"
        }
        return [string[]] $CountryIsos
    }
}
#EndRegion '.\Classes\Get-CountryIso.ps1' 15
#Region '.\Public\Add-STOutboundRelayHostname.ps1' 0
function Add-STOutboundRelayHostname {
    <#
    .SYNOPSIS
    Add Outbound Relay Hostname
     
    .DESCRIPTION
    Add Outbound Relay Hostname
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER UserId
    Target user ID
     
    .PARAMETER Hostname
    New ALias
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Add-OutboundRelayHostname -Url $url -Token $token -Hostname "mail.example.com"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Hostname
    )
    Begin {
        $endpoint = "/restapi/restapi/outbound/hostnames"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Add outbound hostname")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                hostname = $($Hostname)
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Add-STOutboundRelayHostname.ps1' 64
#Region '.\Public\Add-STRbl.ps1' 0
function Add-STRbl {
    <#
    .SYNOPSIS
    Adds an RBL to the system. It will be added at the end of the list.
     
    .DESCRIPTION
    Adds an RBL to the system. It will be added at the end of the list.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Rbl
    New Rbl
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Add-STRbl -Url $url -Token $token -Rbl "zen.spamhaus.org"
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Rbl
    )
    Begin {
        $endpoint = "/restapi/rbl"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Add Alias to user")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                rbl = "$($Rbl)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Add-STRbl.ps1' 62
#Region '.\Public\Add-STSenderBasedSmarthost.ps1' 0
function Add-STSenderBasedSmarthost {
    <#
    .SYNOPSIS
    Add a sender-based Smarthost.
     
    .DESCRIPTION
    Add a sender-based Smarthost.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Sender
    The sender to match on. It can either be a domain (preceded by an @ symbol), or an email address.
     
    .PARAMETER Smarthost
    Address to send mail to. Has to be either an FQDN or IP (IPv4 or IPv6).
    .PARAMETER Port
    The port to deliver mail to at the smarthost address.
 
    Default value: 25
    .PARAMETER NeedAuth
    If authentication is required for the smarthost address.
 
    Default value: false
    .PARAMETER Credential
    [PSCredential] The Credentials to authenticate against the smarthost. Required if needauth is true.
    .PARAMETER Comment
    Comment
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Add-STSenderBasedSmarthost -Url $url -Token $token -Sender "user@example.com" -Smarthost "1.1.1.1" -Port 25
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '(^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9]+\.)*([a-z]+|xn\-\-[a-z0-9]+)\.?$|^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$)'))
            {
                throw "Invalid IP or FQDN"
            }
            return $true
        })]
        [string]$Smarthost,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Port = 25,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$NeedAuth,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [pscredential]$Credential = $(if($NeedAuth){throw "when 'NeedAuth' is used, the parameter 'Credential' is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,255)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost/sender"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Add Sender-based Smarthost")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                sender = $Sender
                smarthost = $Smarthost
                port=$Port
            }
            if($PSBoundParameters.ContainsKey("NeedAuth"))
            {
                $body['needauth'] = $NeedAuth
            }
            if($PSBoundParameters.ContainsKey("Credential"))
            {
                $body['auth_user'] = $Credential.UserName
                $body['auth_password'] = $Credential.GetNetworkCredential().Password
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body['comment'] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Add-STSenderBasedSmarthost.ps1' 110
#Region '.\Public\Add-STUserAliasEmail.ps1' 0
function Add-STUserAliasEmail {
    <#
    .SYNOPSIS
    Add aliases to a User. Aliases are used to merge quarantines together for multiple email addresses.
     
    .DESCRIPTION
    Add aliases to a User. Aliases are used to merge quarantines together for multiple email addresses.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER UserId
    Target user ID
     
    .PARAMETER EmailAddress
    New ALias
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Add-STUserAliasEmail -Url $url -Token $token -UserId 1234 -EmailAddress "alias@example.com"
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$'))
            {
                throw "Invalid Email address"
            }
            return $true
        })]
        [string]$EmailAddress
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Add Alias to user")
        {
            $api = "$($Url)$($endpoint)/$($UserId)/aliases"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                email = "$($EmailAddress)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Add-STUserAliasEmail.ps1' 74
#Region '.\Public\Approve-STQuarantinedEmailRelease.ps1' 0
function Approve-STQuarantinedEmailRelease {
    <#
    .SYNOPSIS
    Release a quarantined mail to the intended recipient or forward to another address (such as an administrator).
     
    .DESCRIPTION
    Release a quarantined mail to the intended recipient or forward to another address (such as an administrator).
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
     
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Approve-STQuarantinedEmailRelease -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$QuarantineId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Secret,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '^(?:(?!.*?[.]{2})[a-zA-Z0-9](?:[a-zA-Z0-9.+!%-]{1,64}|)|\"[a-zA-Z0-9.+!% -]{1,64}\")@[a-zA-Z0-9][a-zA-Z0-9.-]+(.[a-z]{2,}|.[0-9]{1,})$'))
            {
                throw "Invalid Email address"
            }
            return $true
        })]
        [string]$ForwardTo
    )
    Begin {
        $endpoint = "/restapi/quarantine"
        [array]$Result = @()
        [hahstable]$body = @{
            secret_id = $Secret
        }
    }
    Process {
        if($PSCmdlet.ShouldProcess($QuarantineId),"Release a quarantined mail ")
        {
            $api = "$($Url)$($endpoint)/$($QuarantineId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("ForwardTo"))
            {
                $body["forward_to"] = $ForwardTo
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Approve-STQuarantinedEmailRelease.ps1' 76
#Region '.\Public\Disable-STClientCertificate.ps1' 0
function Disable-STClientCertificate {
    <#
    .SYNOPSIS
    Disables client certificate, unsetting any SSL certifcate set to be used.
     
    .DESCRIPTION
    Disables client certificate, unsetting any SSL certifcate set to be used.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Disable-STClientCertificate -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/tls"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($TlsPolicyId),"Disable Client Certificate")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Disable-STClientCertificate.ps1' 54
#Region '.\Public\Disable-STMfa.ps1' 0
function Enable-STMfa{
    <#
    .SYNOPSIS
    Disables two factor authentication for the Authenticated User.
     
    .DESCRIPTION
    Disables two factor authentication for the Authenticated User.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Disable-STMfa -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/auth/two-factor-auth"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Disable MFA for Authenticated User"))
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Disable-STMfa.ps1' 53
#Region '.\Public\Disable-STRbl.ps1' 0
function Disable-STRbl {
    <#
    .SYNOPSIS
    Disables a RBL
     
    .DESCRIPTION
    Disables a RBL
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Disable-STRbl -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Rbl

    )
    Begin {
        $endpoint = "/restapi/rbl"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Disable RBL")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Disable-STRbl.ps1' 56
#Region '.\Public\Enable-STHideInternalNetwork.ps1' 0
function Enable-STHideInternalNetwork {
    <#
    .SYNOPSIS
    Hide Internal Networks hides the IPs from the SpamTitan Trusted Networks from appearing in the headers of Outbound Mail
     
    .DESCRIPTION
    Hide Internal Networks hides the IPs from the SpamTitan Trusted Networks from appearing in the headers of Outbound Mail
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Enable-STHideInternalNetwork -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/outbound/internalip"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Hide Internal Networks hides the IPs from the SpamTitan Trusted Networks from appearing in the headers of Outbound Mail")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                enabled = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $body -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Enable-STHideInternalNetwork.ps1' 58
#Region '.\Public\Enable-STMfa.ps1' 0
function Enable-STMfa{
    <#
    .SYNOPSIS
    Enables two factor authentication for the Authenticated User.
     
    .DESCRIPTION
    Enables two factor authentication for the Authenticated User.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Code
    The 6 digit code provided by the user. This parameter is required.
 
    .PARAMETER Secret
    This is required to validate the one time password.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Enable-STMfa -Url $url -Token $token -Code '123456' -Secret "mysupersecret"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Code,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Secret
    )
    Begin {
        $endpoint = "/restapi/auth/two-factor-auth"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Enable MFA for Authenticated User"))
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                code = "$($Code)"
                secret = "$($Secret)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Enable-STMfa.ps1' 67
#Region '.\Public\Enable-STOutboundDomainVerification.ps1' 0
function Enable-STOutboundDomainVerification {
    <#
    .SYNOPSIS
    Set the enabled status of the outbound domain verification
     
    .DESCRIPTION
    Set the enabled status of the outbound domain verification. When enabled, SpamTitan will check that any mail coming from a trusted network is either coming from or going to a domain that is listed in the Domains table.
    This prevents viruses that may have gotten into your network from sending Spam from domains you do not manage out onto the internet.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Enable-STOutboundDomainVerification -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/outbound/trusted/verify"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Enable Outbound Domain Verification")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                enabled = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $body -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Enable-STOutboundDomainVerification.ps1' 59
#Region '.\Public\Enable-STRateControl.ps1' 0
function Enable-STRateControl {
    <#
    .SYNOPSIS
    Sets the enabled status of Rate Controls
     
    .DESCRIPTION
    Sets the enabled status of Rate Controls
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Enable-STRateControl -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/rate-controls"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set the enabled status of Rate Controls")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Enable-STRateControl.ps1' 55
#Region '.\Public\Get-STAllowedIp.ps1' 0
function Get-STAllowedIp {
    <#
    .SYNOPSIS
    List all allowed IPs
     
    .DESCRIPTION
    List all allowed IPs
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowedIp -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$AllowedIpId
    )
    Begin {
        $endpoint = "/restapi/ip/allow"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("AllowedIpId"))
        {
            $api = "$($api.split('?')[0])/$($AllowedIpId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STAllowedIp.ps1' 74
#Region '.\Public\Get-STAllowList.ps1' 0
function Get-STAllowList {
    <#
    .SYNOPSIS
    Returns one or a list of all allow-listed emails and/or domains.
     
    .DESCRIPTION
    Returns one or a list of all allow-listed emails and/or domains.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER AllowListId
    ID of the targed allowed list
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowList -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowList -Url $url -Token $token -Domain "example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowList -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowList -Url $url -Token $token -UserId "user@example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAllowList -Url $url -Token $token -AllowListId 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$AllowListId
    )
    Begin {
        $endpoint = "/restapi/allow-list"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/allow-list?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)/restapi/domains/$($Domain)/allow-list?results=500&page=" + "$($page)"
            
        }
        if($PSBoundParameters.ContainsKey("UserId"))
        {
            $api = "$($Url)/restapi/users/$($UserId)/allow-list?results=500&page=" + "$($page)"
            
        }
        if($PSBoundParameters.ContainsKey("AllowListId"))
        {
            $api = "$($api.split('?')[0])/$($AllowListId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STAllowList.ps1' 127
#Region '.\Public\Get-STArcKey.ps1' 0
function Get-STArcKey {
    <#
    .SYNOPSIS
    List the keys available to the system for ARC signing.
     
    .DESCRIPTION
    List the keys available to the system for ARC signing.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER ArcKey
    Target Key ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STArcKey -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STArcKey -Url $url -Token $token -ArcKeyId 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$ArcKeyId


    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc/keys"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("ArcKeyId"))
        {
            $api = "$($Url)$($endpoint)/$($ArcKeyId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STArcKey.ps1' 83
#Region '.\Public\Get-STArcKeyInUse.ps1' 0
function Get-STArcKeyInUse {
    <#
    .SYNOPSIS
    List the keys available to the system for ARC signing.
     
    .DESCRIPTION
    List the keys available to the system for ARC signing.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STArcKeyInUse -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token


    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            $Result += $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STArcKeyInUse.ps1' 55
#Region '.\Public\Get-STAuthenticationMethod.ps1' 0
function Get-STAuthenticationMethod {
    <#
    .SYNOPSIS
    Returns a list of all domains' authentication methods.
     
    .DESCRIPTION
    Returns a list of all domains' authentication methods.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAuthenticationMethod -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain
    )
    Begin {
        $endpoint = "/restapi/domains"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/auth?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 100)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STAuthenticationMethod.ps1' 61
#Region '.\Public\Get-STAuthorizationToken.ps1' 0
function Get-STAuthorizationToken {
    <#
    .SYNOPSIS
    Returns a list of all authorization tokens for the user.
     
    .DESCRIPTION
    Returns a list of all authorization tokens for the user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STAuthorizationToken -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/auth/tokens"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 100)
        
    }
    End {
        return $Result
    }
}


#EndRegion '.\Public\Get-STAuthorizationToken.ps1' 60
#Region '.\Public\Get-STBlockedIp.ps1' 0
function Get-STBlockedIp {
    <#
    .SYNOPSIS
    List all allowed IPs
     
    .DESCRIPTION
    List all allowed IPs
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockedIp -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$BlockedIpId
    )
    Begin {
        $endpoint = "/restapi/ip/block"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("BlockedIpId"))
        {
            $api = "$($api.split('?')[0])/$($BlockedIpId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STBlockedIp.ps1' 74
#Region '.\Public\Get-STBlockList.ps1' 0
function Get-STBlockList {
    <#
    .SYNOPSIS
    Returns a list of all blocked emails and/or domains
     
    .DESCRIPTION
    Returns a list of all blocked emails and/or domains
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER BlockListId
    ID of the targed blocked List
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -Domain "example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -UserId "user@example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -AllowListId 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$BlockListId
    )
    Begin {
        $endpoint = "/restapi/block-list"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/block-list?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)/restapi/domains/$($Domain)/block-list?results=500&page=" + "$($page)"
            
        }
        if($PSBoundParameters.ContainsKey("UserId"))
        {
            $api = "$($Url)/restapi/users/$($UserId)/block-list?results=500&page=" + "$($page)"
            
        }
        if($PSBoundParameters.ContainsKey("BlockListId"))
        {
            $api = "$($api.split('?')[0])/$($BlockListId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STBlockList.ps1' 127
#Region '.\Public\Get-STClientCertificate.ps1' 0
function Get-STClientCertificate {
    <#
    .SYNOPSIS
    Show what certificate is used for the Client Certificate.
     
    .DESCRIPTION
    Show what certificate is used for the Client Certificate. If a receiving server requests a Client Certificate, this is the certificate that SpamTitan will send.
    Client Certificates are only sent if a receiving server requests it. SecureMail servers will tend to request client certificates to validate the sending server.
    NOTE: Do not enable this unless required.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STClientCertificate -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/tls/client-cert"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STClientCertificate.ps1' 54
#Region '.\Public\Get-STConfiguration.ps1' 0
function Get-STConfiguration {
    <#
    .SYNOPSIS
    Provides the current values of SpamTitan configuration.
     
    .DESCRIPTION
    Returns whether Sandboxing is enabled.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STConfiguration -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/config"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            $Result += $temp.config
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STConfiguration.ps1' 52
#Region '.\Public\Get-STDkim.ps1' 0
function Get-STDkim {
    <#
    .SYNOPSIS
    List all the DKIMs.
     
    .DESCRIPTION
    List all the DKIMs.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkim -Url $url -Token $token -Domain 'example.com'
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkim -Url $url -Token $token -Domain 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain
    )
    Begin {
        $endpoint = "/restapi/domains"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Domain)/dkim?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDkim.ps1' 69
#Region '.\Public\Get-STDkimAdspStatus.ps1' 0
function Get-STDkimAdspStatus {
    <#
    .SYNOPSIS
    Shows whether ADSP is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether ADSP is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimAdspStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/adsp"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDkimAdspStatus.ps1' 52
#Region '.\Public\Get-STDkimBypassedIp.ps1' 0
function Get-STDkimBypassedIp {
    <#
    .SYNOPSIS
    List IPs that are exempt from DKIM checking.
     
    .DESCRIPTION
    List IPs that are exempt from DKIM checking.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER DkimBypassedIp
    Target bypassed IP ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimBypassedIp -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimBypassedIp -Url $url -Token $token -DkimBypassedIp 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DkimBypassedIp

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/bypass"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("DkimBypassedIp"))
        {
            $api = "$($Url)$($endpoint)/$($DkimBypassedIp)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDkimBypassedIp.ps1' 82
#Region '.\Public\Get-STDkimKey.ps1' 0
function Get-STDkimKey {
    <#
    .SYNOPSIS
    Show the authentication settings for a domain.
     
    .DESCRIPTION
    Show the authentication settings for a domain.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER DkimId
    Target DKIM Id.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimKey -Url $url -Token $token -Domain 'example.com' -DkimId 1
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimKey -Url $url -Token $token -Domain 5 -DkimId 1
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DkimId
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Domain)/dkim/$($DkimId)"
        
        $Header  = @{
    
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $Result = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
        }
        catch{
            throw $_.Exception.Message
            return $Result
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDkimKey.ps1' 67
#Region '.\Public\Get-STDkimStatus.ps1' 0
function Get-STDkimStatus {
    <#
    .SYNOPSIS
    Shows whether DKIM checking is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether DKIM checking is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDkimStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDkimStatus.ps1' 51
#Region '.\Public\Get-STDmarcArcHeader.ps1' 0
function Get-STDmarcArcHeader {
    <#
    .SYNOPSIS
    Shows whether or not DMARC will implicitly trust all ARC headers.
     
    .DESCRIPTION
    Shows whether or not DMARC will implicitly trust all ARC headers.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcArcHeader -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/trustarc"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcArcHeader.ps1' 51
#Region '.\Public\Get-STDmarcBypassedIp.ps1' 0
function Get-STDmarcBypassedIp {
    <#
    .SYNOPSIS
    List IPs that are exempt from Dmarc checking.
     
    .DESCRIPTION
    List IPs that are exempt from Dmarc checking.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER DmarcBypassedIp
    Target bypassed IP ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcBypassedIp -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcBypassedIp -Url $url -Token $token -DmarcBypassedIp 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DmarcBypassedIp

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/bypass"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("DmarcBypassedIp"))
        {
            $api = "$($Url)$($endpoint)/$($DmarcBypassedIp)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcBypassedIp.ps1' 82
#Region '.\Public\Get-STDmarcMailingListWhitelist.ps1' 0
function Get-STDmarcMailingListWhitelist {
    <#
    .SYNOPSIS
    Shows whether Dmarc checking is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether Dmarc checking is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcMailingListWhitelist -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/mailinglists"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcMailingListWhitelist.ps1' 51
#Region '.\Public\Get-STDmarcPolicyAction.ps1' 0
function Get-STDmarcPolicyAction {
    <#
    .SYNOPSIS
    Show what action to perform when the DMARC policy says to do $Policy.
     
    .DESCRIPTION
    Show what action to perform when the DMARC policy says to do $Policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Policy
    The action to be setting the action for.
 
    Allowed values: reject, quarantine
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcPolicyAction -Url $url -Token $token -Policy reject
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("reject","quarantine")]
        [string]$Policy
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/actions"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Policy)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcPolicyAction.ps1' 59
#Region '.\Public\Get-STDmarcReportingSetting.ps1' 0
function Get-STDmarcReportingSetting {
    <#
    .SYNOPSIS
    Show the DMARC reporting settings.
     
    .DESCRIPTION
    Show the DMARC reporting settings.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcReportingSetting -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/reporting"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcReportingSetting.ps1' 51
#Region '.\Public\Get-STDmarcStatus.ps1' 0
function Get-STDmarcStatus {
    <#
    .SYNOPSIS
    Shows whether Dmarc checking is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether Dmarc checking is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDmarcStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDmarcStatus.ps1' 51
#Region '.\Public\Get-STDomain.ps1' 0
function Get-STDomain {
    <#
    .SYNOPSIS
    Returns a list of all domains available.
     
    .DESCRIPTION
    Returns a list of all domains available.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    Target GroupId
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomain -Url $url -Token $token
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomain -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomain -Url $url -Token $token -GroupId 5 -Domain "example.com"
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain
    )
    Begin {
        $endpoint = "/restapi/domains"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/domains?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)$($endpoint)/$($Domain)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        if($($PSBoundParameters.ContainsKey("Domain")) -and $($PSBoundParameters.ContainsKey("GroupId")))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/domains/$($Domain)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDomain.ps1' 107
#Region '.\Public\Get-STDomainAuthSetting.ps1' 0
function Get-STDomainAuthSetting {
    <#
    .SYNOPSIS
    Show the authentication settings for a domain.
     
    .DESCRIPTION
    Show the authentication settings for a domain.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomainAuthSetting -Url $url -Token $token -Domain 'example.com'
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomainAuthSetting -Url $url -Token $token -Domain 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Domain)/auth"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $Result = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
        }
        catch{
            throw $_.Exception.Message
            return $Result
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDomainAuthSetting.ps1' 61
#Region '.\Public\Get-STDomainGroup.ps1' 0
function Get-STDomainGroup {
    <#
    .SYNOPSIS
    Lists the Domain Groups
     
    .DESCRIPTION
    Lists the Domain Groups
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomainGroup -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STDomainGroup -Url $url -Token $token -GroupId 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=100&page=$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)$($endpoint)/$($GroupId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 100)
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STDomainGroup.ps1' 76
#Region '.\Public\Get-STGeoblockingExemption.ps1' 0
function Get-STGeoblockingExemption {
    <#
    .SYNOPSIS
    Returns a list of geoblocking sender exemptions
     
    .DESCRIPTION
    Returns a list of geoblocking sender exemptions
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingExemption -Url $url -Token $token
 
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GeoblockingId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DomainId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Email,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("domain", "email", "ip")]
        [string]$Type
    )
    Begin {
        $endpoint = "/restapi/geo-exemptions"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.containskey("GeoblockingId"))
        {
            $api = "$($Url)$($endpoint)/$($GeoblockingId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        if($PSBoundParameters.containskey("GroupId"))
        {
            $api = "$($Url)/domain-groups/$($GroupId)/geo-exemptions"
        }
        if($PSBoundParameters.containskey("Domain"))
        {
            $api = "$($Url)/domains/$($Domain)/geo-exemptions"
        }
        if($PSBoundParameters.containskey("UserId"))
        {
            $api = "$($Url)/users/$($UserId)/geo-exemptions"
        }
        if($PSBoundParameters.containskey("Comment"))
        {
            $api = "$($api)&comment=$($Comment)"
        }
        if($PSBoundParameters.containskey("Domain"))
        {
            $api = "$($api)&domain=$($Domain)"
        }
        if($PSBoundParameters.containskey("Email"))
        {
            $api = "$($api)&email=$($Email)"
        }
        if($PSBoundParameters.containskey("IpAddress"))
        {
            $api = "$($api)&ip=$($IpAddress)"
        }
        if($PSBoundParameters.containskey("Type"))
        {
            $api = "$($api)&type=$($Type)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            $Result += $temp.data
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STGeoblockingExemption.ps1' 115
#Region '.\Public\Get-STGeoblockingRule.ps1' 0
function Get-STGeoblockingRule {
    <#
    .SYNOPSIS
    Returns a list of geoblocking allow and block rules
     
    .DESCRIPTION
    Returns a list of geoblocking allow and block rules
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    Target GroupId
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .PARAMETER UserId
    ID of the target user
 
    .PARAMETER CountryIso
    Target Country ISO code
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingRule -Url $url -Token $token
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingRule -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingRule -Url $url -Token $token -Domain "example.com"
 
    EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingRule -Url $url -Token $token -UserId 5
 
    EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingRule -Url $url -Token $token -CountryIso US
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet([CountryIsos])]
        [string]$CountryIso
    )
    Begin {
        $endpoint = "/restapi/geo-rules"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("UserId"))
        {
            $api = "$($Url)/restapi/users/$($UserId)/geo-rules?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/geo-rules?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)/restapi/domains/$($Domain)/geo-rules?results=500&page=" + "$($page)"
        }
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("CountryIso"))
        {
            $api = "$($api.split('?')[0])/$($CountryIso)"
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STGeoblockingRule.ps1' 117
#Region '.\Public\Get-STGeoblockingStatus.ps1' 0
function Get-STGeoblockingStatus {
    <#
    .SYNOPSIS
    Shows whether Geoblocking is enabled or not.
     
    .DESCRIPTION
    Shows whether Geoblocking is enabled or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingStatus -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingStatus -Url $url -Token $token -GroupId 4
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingStatus -Url $url -Token $token -UserId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STGeoblockingStatus -Url $url -Token $token -Domain 'example.com'
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId

    )
    Begin {
        $endpoint = "/restapi/geoblocking"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.containskey("GroupId"))
        {
            $api = "$($Url)/domain-groups/$($GroupId)/geoblocking/"
        }
        if($PSBoundParameters.containskey("Domain"))
        {
            $api = "$($Url)/domains/$($Domain)/geoblocking/"
        }
        if($PSBoundParameters.containskey("UserId"))
        {
            $api = "$($Url)/users/$($UserId)/geoblocking/"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STGeoblockingStatus.ps1' 85
#Region '.\Public\Get-STHideInternalNetworkStatus.ps1' 0
function Get-STHideInternalNetworkStatus {
    <#
    .SYNOPSIS
    Shows whether Rate Controls are enabled on the system or not.
     
    .DESCRIPTION
    Shows whether Rate Controls are enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STHideInternalNetworkStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/internalip"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STHideInternalNetworkStatus.ps1' 52
#Region '.\Public\Get-STLetsEncryptStatus.ps1' 0
function Get-STLetsEncryptStatus {
    <#
    .SYNOPSIS
    Provides the current status of a LetsEncrypt certificate.
     
    .DESCRIPTION
    Provides the current status of a LetsEncrypt certificate.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STLetsEncryptStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/ssl/lets-encrypt"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STLetsEncryptStatus.ps1' 51
#Region '.\Public\Get-STLicenseKey.ps1' 0
function Get-STLicenseKey {
    <#
    .SYNOPSIS
    Provides information about who the license is registered to.
     
    .DESCRIPTION
    Provides information about who the license is registered to.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER GetLicense
    Used to download the license file from the SpamTitan system
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STLicenseKey -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$GetLicense
    )
    Begin {
        $endpoint = "/restapi/license/key"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("GetLicense"))
        {
            $Header  = @{
                "Accept" = "application/license-key"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STLicenseKey.ps1' 64
#Region '.\Public\Get-STLicenseStatus.ps1' 0
function Get-STLicenseStatus {
    <#
    .SYNOPSIS
    Provides details of the current status of the currently applied license.
     
    .DESCRIPTION
    Provides details of the current status of the currently applied license.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STLicenseStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/license"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STLicenseStatus.ps1' 51
#Region '.\Public\Get-STLicenseUsageStatus.ps1' 0
function Get-STLicenseUsageStatus {
    <#
    .SYNOPSIS
    Show a summary of licensing information, either for the system, domain, or domain group.
     
    .DESCRIPTION
    Show a summary of licensing information, either for the system, domain, or domain group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Period
    The period in which to specify the summary for. If undefined, it will show an all-time report.
 
    Allowed values: today, yesterday, thisweek, lastweek, thismonth, lastmonth
     
    .PARAMETER StartDate
    If the period is unset, the start will be the first date for the summary
     
    .PARAMETER EndDate
    If the period is unset, the end will be the last date for the summary
     
    .PARAMETER Domain
    The domain to provide license usage stats for. This is the domain, not the ID.
     
    .PARAMETER Group
    The domain group to provide license usage stats for. This is the domain group's name
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STLicenseUsageStatus -Url $url -Token $token -StartDate $(Get-Date).AddDays(-30) -EndDate $(Get-Date)
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("today", "yesterday", "thisweek", "lastweek", "thismonth", "lastmonth")]
        [string]$Period,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$StartDate,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$EndDate,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Group
    )
    Begin {
        $endpoint = "/restapi/reports/license-usage?start=$($StartDate.ToString('yyyy-mm-dd'))&end=$($EndDate.ToString('yyyy-mm-dd'))"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("Period"))
        {
            $api = "$($api)&period=$($Period)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($api)&domain=$($Domain)"
        }
        if($PSBoundParameters.ContainsKey("Group"))
        {
            $api = "$($api)&domain_group=$($Group)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STLicenseUsageStatus.ps1' 91
#Region '.\Public\Get-STMailQueue.ps1' 0
function Get-STMailQueue {
    <#
    .SYNOPSIS
    Show a summary of mail in the SpamTitan's queues.
     
    .DESCRIPTION
    Show a summary of mail in the SpamTitan's queues.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Queue
    The queue to list.
 
    Default value: all
 
    Allowed values: all, active, incoming, deferred
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STMailQueue -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STMailQueue -Url $url -Token $token -Queue Deferred
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("all", "active", "incoming", "deferred")]
        [string]$Queue = 'all'

    )
    Begin {
        $endpoint = "/restapi/mail-queue"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Queue)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return [pscustomobject] @{
                Endpoint = $Url
                Active = $temp.active
                Deferred = $temp.deferred
                Incoming = $temp.incoming
                Total = $temp.total
            }
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STMailQueue.ps1' 73
#Region '.\Public\Get-STMessageTrace.ps1' 0
function Get-STMessageTrace {
    <#
    .SYNOPSIS
    Search for messages for a recipient in a specific time period
     
    .DESCRIPTION
    Search for messages for a recipient in a specific time period
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Cluster
    Whether or not to show messages from the full cluster or just the local node.
 
    Default value: false
     
    .PARAMETER Subject
    Filter by the subject. Use of an asterisk (*) will mark a wildcard.
     
    .PARAMETER Sender
    Filter by the sender. Use of an asterisk (*) will mark a wildcard
     
    .PARAMETER Recipient
    Filter by the recipient. Use of an asterisk (*) will mark a wildcard.
     
    .PARAMETER Score
    Filter by Score.
     
    .PARAMETER StartDate
    Start date for searching quarantine.
     
    .PARAMETER EndDate
    Start date for searching quarantine.
 
    Default value: now
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STMessageTrace -Url $url -Token $token -Cluster -Recipient 'username*' -StartDate $(Get-Date).AddDays(-3) -EndDate $(Get-Date)
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Subject,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,

        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Recipient,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Score,

        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$StartDate,

        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$EndDate

    )
    Begin {
        $endpoint = "/restapi/history/trace"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?recipient=$($Recipient)&start_date=$($StartDate.ToString('yyyy-MM-dd'))&end_date=$($EndDate.ToString('yyyy-MM-dd'))"
        
        if($PSBoundParameters.ContainsKey("Subject")) {
            $api = "$($api)&subject=$($Subject)"
        }
        if($PSBoundParameters.ContainsKey("Sender")) {
            $api = "$($api)&sender=$($Sender)"
        }
        if($PSBoundParameters.ContainsKey("Score")) {
            $api = "$($api)&score=$($Score)"
        }
        $api = "$($api)&results=500&page=" + "$($page)"
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STMessageTrace.ps1' 114
#Region '.\Public\Get-STOutboundDomainVerification.ps1' 0
function Get-STOutboundDomainVerification {
    <#
    .SYNOPSIS
    Check the enabled status of the outbound domain verification. When enabled, SpamTitan will check that any mail coming from a trusted network is either coming from or going to a domain that is listed in the Domains table.
    This prevents viruses that may have gotten into your network from sending Spam from domains you do not manage out onto the internet
     
    .DESCRIPTION
    Check the enabled status of the outbound domain verification. When enabled, SpamTitan will check that any mail coming from a trusted network is either coming from or going to a domain that is listed in the Domains table.
    This prevents viruses that may have gotten into your network from sending Spam from domains you do not manage out onto the internet
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STOutboundDomainVerification -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/reject"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STOutboundDomainVerification.ps1' 54
#Region '.\Public\Get-STOutboundPolicy.ps1' 0
function Get-STOutboundPolicy {
    <#
    .SYNOPSIS
    Shows whether Rate Controls are enabled on the system or not.
     
    .DESCRIPTION
    Shows whether Rate Controls are enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STOutboundPolicy -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/policy"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STOutboundPolicy.ps1' 52
#Region '.\Public\Get-STOutboundRelay.ps1' 0
function Get-STOutboundRelay {
    <#
    .SYNOPSIS
    List hostnames of outbound relays. This lists the hostname of the relay (or relays) that you send your outbound mail through.
     
    .DESCRIPTION
    List hostnames of outbound relays. This lists the hostname of the relay (or relays) that you send your outbound mail through. This is used to 'rescue' legitimate bounce messages that were generated in response to mail you really did send.
    If a bounce message is found, and it contains one of these hostnames in a Received header in the bounced message, it will not be marked as a blowback virus-bounce.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STOutboundRelay-Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/outbound/hostnames"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result | ForEach-Object {[pscustomobject]@{OutboundRelay = $_}}
    }
}
#EndRegion '.\Public\Get-STOutboundRelay.ps1' 60
#Region '.\Public\Get-STPatternFilter.ps1' 0
function Get-STPatternFilter {
    <#
    .SYNOPSIS
    Returns a list of all pattern filters.
     
    .DESCRIPTION
    Returns a list of all pattern filters.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
     
    .PARAMETER PatternId
    ID of the targed Pattern Id
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -Domain "example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -UserId "user@example.com"
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STBlockList -Url $url -Token $token -Filter block-list
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$PatternId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("allow-list","block-list","testmode")]
        [string]$Filter
    )
    Begin {
        $endpoint = "/restapi/patterns"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/patterns?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)/restapi/domains/$($Domain)/patterns?results=500&page=" + "$($page)"
            
        }
        if($PSBoundParameters.ContainsKey("Filter"))
        {
            $api = "$($api.split('?')[0])/$($Filter)?results=500&page=" + "$($page)"

        }
        if($PSBoundParameters.ContainsKey("PatternId"))
        {
            $api = "$($api.split('?')[0])/$($PatternId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STPatternFilter.ps1' 125
#Region '.\Public\Get-STQuarantine.ps1' 0
function Get-STQuarantine {
    <#
    .SYNOPSIS
    Short description
     
    .DESCRIPTION
    Long description
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Type
    The type of quarantine to display.
 
    Default value: all
 
    Allowed values: virus, spam, archive, banned, content-filter, all
     
    .PARAMETER ShowDeleted
    Whether or not to show the deleted types of quarantined items instead of the non-deleted items.
 
    Default value: false
     
    .PARAMETER ShowCluster
    Whether or not to show messages from the full cluster or just the local node.
 
    Default value: false
     
    .PARAMETER Subject
    Filter by the subject. Use of an asterisk (*) will mark a wildcard.
     
    .PARAMETER Sender
    Filter by the sender. Use of an asterisk (*) will mark a wildcard
     
    .PARAMETER Recipient
    Filter by the recipient. Use of an asterisk (*) will mark a wildcard.
     
    .PARAMETER GroupName
    Filter by domain group name.
     
    .PARAMETER GroupId
    Filter by domain group identifier.
     
    .PARAMETER Domain
    Filter by domain. Use "@." for Global.
     
    .PARAMETER DomainId
    Filter by domain identifier.
     
    .PARAMETER Score
    Filter by Score.
     
    .PARAMETER StartDate
    Start date for searching quarantine.
     
    .PARAMETER EndDate
    Start date for searching quarantine.
 
    Default value: now
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STQuarantine -Url $url -Token $token -ShowCluster -Recipient 'username*' -StartDate $(Get-Date).AddDays(-3) -EndDate $(Get-Date)
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("virus", "spam", "archive", "banned", "content-filter", "all")]
        [string]$Type = 'all',

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ShowDeleted,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ShowCluster,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Subject,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Recipient,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupName,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DomainId,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Score,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [datetime]$StartDate,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [datetime]$EndDate




    )
    Begin {
        $endpoint = "/restapi/quarantine"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?type=$($Type)&show_deleted=$($ShowDeleted)&cluster=$($ShowCluster)"
        
        if($PSBoundParameters.ContainsKey("Subject")) {
            $api = "$($api)&subject=$($Subject)"
        }
        if($PSBoundParameters.ContainsKey("Sender")) {
            $api = "$($api)&sender=$($Sender)"
        }
        if($PSBoundParameters.ContainsKey("Recipient")) {
            $api = "$($api)&recipient=$($Recipient)"
        }
        if($PSBoundParameters.ContainsKey("GroupName")) {
            $api = "$($api)&domain_group=$($GroupName)"
        }
        if($PSBoundParameters.ContainsKey("GroupId")) {
            $api = "$($api)&domain_group_id=$($GroupId)"
        }
        if($PSBoundParameters.ContainsKey("Domain")) {
            $api = "$($api)&domain=$($Domain)"
        }
        if($PSBoundParameters.ContainsKey("DomainId")) {
            $api = "$($api)&domain_id=$($DomainId)"
        }
        if($PSBoundParameters.ContainsKey("Score")) {
            $api = "$($api)&score=$($Score)"
        }
        if($PSBoundParameters.ContainsKey("StartDate")) {
            $api = "$($api)&start_date=$($StartDate.ToString('yyyy-MM-dd'))"
        }
        if($PSBoundParameters.ContainsKey("EndDate")) {
            $api = "$($api)&end_date=$($EndDate.ToString('yyyy-MM-dd'))"
        }
        $api = "$($api)&results=500&page=" + "$($page)"
        
        


        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STQuarantine.ps1' 187
#Region '.\Public\Get-STQuarantinedEmail.ps1' 0
function Get-STQuarantinedEmail {
    <#
    .SYNOPSIS
    Show the details of a Quarantined Mail
     
    .DESCRIPTION
    Show the details of a Quarantined Mail
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STQuarantinedEmail -Url $url -Token $token -QurantineId '0c7fuE5s87wJ'
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STQuarantinedEmail -Url $url -Token $token -QurantineId '0c7fuE5s87wJ' -ShowEmail
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$QurantineId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [switch]$ShowEmail
    )
    Begin {
        $endpoint = "/restapi/quarantine/report"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($QurantineId)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.containsKey("ShowEmail"))
        {
            $Header  = @{
                "Accept" = "message/rfc822"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STQuarantinedEmail.ps1' 68
#Region '.\Public\Get-STRateControlPolicy.ps1' 0
function Get-STRateControlPolicy {
    <#
    .SYNOPSIS
    Lists the Rate Control policies.
     
    .DESCRIPTION
    Lists the Rate Control policies.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER PolicyId
    Target Policy ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRateControlPolicy -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRateControlPolicy -Url $url -Token $token -PolicyId 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$PolicyId


    )
    Begin {
        $endpoint = "/restapi/rate-controls/policies"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("PolicyId"))
        {
            $api = "$($Url)$($endpoint)/$($PolicyId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STRateControlPolicy.ps1' 83
#Region '.\Public\Get-STRateControlStatus.ps1' 0
function Get-STRateControlStatus {
    <#
    .SYNOPSIS
    Shows whether Rate Controls are enabled on the system or not.
     
    .DESCRIPTION
    Shows whether Rate Controls are enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRateControlStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/rate-controls"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STRateControlStatus.ps1' 52
#Region '.\Public\Get-STRbl.ps1' 0
function Get-STRbl {
    <#
    .SYNOPSIS
    List all allowed IPs
     
    .DESCRIPTION
    List all allowed IPs
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRbl-Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/rbl"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result | ForEach-Object {[pscustomobject]@{RBL = $_}}
    }
}
#EndRegion '.\Public\Get-STRbl.ps1' 60
#Region '.\Public\Get-STRblBybassedIp.ps1' 0
function Get-STRblBybassedIp {
    <#
    .SYNOPSIS
    Shows an IP that bypasses RBL checking on the appliance.
     
    .DESCRIPTION
    Shows an IP that bypasses RBL checking on the appliance.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER RblBypassedIpId
    Target bypassed IP ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRblBybassedIp -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STRblBybassedIp -Url $url -Token $token -RblBypassedIpId 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$RblBypassedIpId

    )
    Begin {
        $endpoint = "/restapi/rbl/bypass"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("RblBypassedIpId"))
        {
            $api = "$($Url)$($endpoint)/$($RblBypassedIpId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STRblBybassedIp.ps1' 83
#Region '.\Public\Get-STSandboxStatus.ps1' 0
function Get-STSandboxStatus {
    <#
    .SYNOPSIS
    Returns whether Sandboxing is enabled.
     
    .DESCRIPTION
    Returns whether Sandboxing is enabled.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSandboxStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/atp/sandboxing"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSandboxStatus.ps1' 52
#Region '.\Public\Get-STSaslSetting.ps1' 0
function Get-STSaslSetting {
    <#
    .SYNOPSIS
    Show the SASL settings
     
    .DESCRIPTION
    Show the SASL settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSaslSetting -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/rate-controls"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSaslSetting.ps1' 52
#Region '.\Public\Get-STScanSummary.ps1' 0
function Get-STScanSummary {
    <#
    .SYNOPSIS
    Show a summary of mail delivered to the SpamTitan system.
     
    .DESCRIPTION
    Show a summary of mail delivered to the SpamTitan system.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Period
    The period in which to specify the summary for. If undefined, it will show an all-time report.
 
    Allowed values: today, yesterday, thisweek, lastweek, thismonth, lastmonth
     
    .PARAMETER StartDate
    If the period is unset, the start will be the first date for the summary
     
    .PARAMETER EndDate
    If the period is unset, the end will be the last date for the summary
     
    .PARAMETER Domain
    The domain to provide license usage stats for. This is the domain, not the ID.
     
    .PARAMETER Group
    The domain group to provide license usage stats for. This is the domain group's name
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STScanSummary -Url $url -Token $token -StartDate $(Get-Date).AddDays(-30) -EndDate $(Get-Date)
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("today", "yesterday", "thisweek", "lastweek", "thismonth", "lastmonth")]
        [string]$Period,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$StartDate,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [datetime]$EndDate,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Group
    )
    Begin {
        $endpoint = "/restapi/reports/scan-summary?start=$($StartDate.ToString('yyyy-mm-dd'))&end=$($EndDate.ToString('yyyy-mm-dd'))"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("Period"))
        {
            $api = "$($api)&period=$($Period)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($api)&domain=$($Domain)"
        }
        if($PSBoundParameters.ContainsKey("Group"))
        {
            $api = "$($api)&domain_group=$($Group)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STScanSummary.ps1' 91
#Region '.\Public\Get-STSenderBasedSmarthost.ps1' 0
function Get-STSenderBasedSmarthost {
    <#
    .SYNOPSIS
    List sender-based Smarthosts.
     
    .DESCRIPTION
    List sender-based Smarthosts.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER SmarthostId
    Target Smarthost ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSenderBasedSmarthost -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSenderBasedSmarthost -Url $url -Token $token -SmarthostId 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SmarthostId


    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost/sender"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("SmarthostId"))
        {
            $api = "$($Url)$($endpoint)/$($SmarthostId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSenderBasedSmarthost.ps1' 83
#Region '.\Public\Get-STServerWideSmarthost.ps1' 0
function Get-STServerWideSmarthost {
    <#
    .SYNOPSIS
    Show the server-wide smarthost settings.
     
    .DESCRIPTION
    Show the server-wide smarthost settings.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STServerWideSmarthost -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STServerWideSmarthost.ps1' 52
#Region '.\Public\Get-STSpamUpdate.ps1' 0
function Get-STSpamUpdate {
    <#
    .SYNOPSIS
    Show a summary of spam updates. This provides information on the frequency of updates and when the last update was
     
    .DESCRIPTION
    Show a summary of spam updates. This provides information on the frequency of updates and when the last update was
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSpamUpdate -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/reports/spam-update"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSpamUpdate.ps1' 52
#Region '.\Public\Get-STSpfBypassedIp.ps1' 0
function Get-STSpfBypassedIp {
    <#
    .SYNOPSIS
    Shows an IP that bypasses RBL checking on the appliance.
     
    .DESCRIPTION
    Shows an IP that bypasses RBL checking on the appliance.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER SpfBypassedIp
    Target bypassed IP ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSpfBypassedIp -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSpfBypassedIp -Url $url -Token $token -SpfBypassedIp 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpfBypassedIp

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/bypass"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("SpfBypassedIp"))
        {
            $api = "$($Url)$($endpoint)/$($SpfBypassedIp)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSpfBypassedIp.ps1' 82
#Region '.\Public\Get-STSpfDmarcRejectionStatus.ps1' 0
function Get-STSpfDmarcRejectionStatus {
    <#
    .SYNOPSIS
    Shows whether SPF rejection is enabled for none DMARC policies
     
    .DESCRIPTION
    Shows whether SPF rejection is enabled for none DMARC policies
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSpfDmarcRejectionStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/reject/dmarc-none"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSpfDmarcRejectionStatus.ps1' 52
#Region '.\Public\Get-STSpfRejectionStatus.ps1' 0
function Get-STSpfRejectionStatus {
    <#
    .SYNOPSIS
    Shows whether SPF rejection is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether SPF rejection is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSpfRejectionStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/reject"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSpfRejectionStatus.ps1' 52
#Region '.\Public\Get-STSupportPortStatus.ps1' 0
function Get-STSupportPortStatus {
    <#
    .SYNOPSIS
    Get the current support port status.
     
    .DESCRIPTION
    Get the current support port status.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSupportPortStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/support-port"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSupportPortStatus.ps1' 52
#Region '.\Public\Get-STSystemTlsPolicy.ps1' 0
function Get-STSystemTlsPolicy {
    <#
    .SYNOPSIS
    Show the System's TLS Policy.
     
    .DESCRIPTION
    Show the System's TLS Policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STSystemTlsPolicy -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/outbound/tls/policy"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STSystemTlsPolicy.ps1' 52
#Region '.\Public\Get-STTlsPolicy.ps1' 0
function Get-STTlsPolicy {
    <#
    .SYNOPSIS
    List the TLS Exception Policies. These are per-recipient TLS Policies.
     
    .DESCRIPTION
    List the TLS Exception Policies. These are per-recipient TLS Policies.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER TlsPolicyId
    ID of the targed policy
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STTlsPolicy -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STTlsPolicy -Url $url -Token $token -TlsPolicyId 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$TlsPolicyId
    )
    Begin {
        $endpoint = "/restapi/outbound/tls"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("TlsPolicyId"))
        {
            $api = "$($api.split('?')[0])/$($TlsPolicyId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STTlsPolicy.ps1' 84
#Region '.\Public\Get-STTrustedNetwork.ps1' 0
function Get-STTrustedNetwork {
    <#
    .SYNOPSIS
    SpamTitan will mark mails from a selection of trusted IP Networks as outbound. These are known as "Trusted Networks".
    SpamTitan can also verify that mail coming from these IPs are from domains set up in the SpamTitan appliance, thus preventing a good portion of outbound spam
     
    .DESCRIPTION
    SpamTitan will mark mails from a selection of trusted IP Networks as outbound. These are known as "Trusted Networks".
    SpamTitan can also verify that mail coming from these IPs are from domains set up in the SpamTitan appliance, thus preventing a good portion of outbound spam
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER TrustedNetworkId
    ID of the targed trusted network
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STTrustedNetwork -Url $url -Token $token
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STTrustedNetwork -Url $url -Token $token -TrustedNetworkId 5
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$TrustedNetworkId
    )
    Begin {
        $endpoint = "/restapi/outbound/trusted"
        $page = 1
        [array]$Result = @()
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("TrustedNetworkId"))
        {
            $api = "$($api.split('?')[0])/$($TrustedNetworkId)"
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                return $temp
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }

        }
        
        
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STTrustedNetwork.ps1' 100
#Region '.\Public\Get-STUser.ps1' 0
function Get-STUser {
    <#
    .SYNOPSIS
    Lists the users on the system.
     
    .DESCRIPTION
    Lists the users on the system.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    Target GroupId
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .PARAMETER UserId
    ID of the target user
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STUser -Url $url -Token $token
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STUser -Url $url -Token $token -GroupId 5
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STUser -Url $url -Token $token -GroupId 5 -Domain "example.com"
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId
    )
    Begin {
        $endpoint = "/restapi/users"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)?results=500&page=" + "$($page)"
        if($PSBoundParameters.ContainsKey("GroupId"))
        {
            $api = "$($Url)/restapi/domain-groups/$($GroupId)/users?results=500&page=" + "$($page)"
        }
        if($PSBoundParameters.ContainsKey("Domain"))
        {
            $api = "$($Url)/restapi/domains/$($Domain)/users?results=500&page=" + "$($page)"
        }
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        if($PSBoundParameters.ContainsKey("UserId"))
        {
            $api = "$($api.split('?')[0])/$($UserId)"
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STUser.ps1' 97
#Region '.\Public\Get-STVirusUpdate.ps1' 0
function Get-STVirusUpdate {
    <#
    .SYNOPSIS
    Show a summary of spam updates. This provides information on the frequency of updates and when the last update was
     
    .DESCRIPTION
    Show a summary of spam updates. This provides information on the frequency of updates and when the last update was
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Get-STVirusUpdate -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/reports/virus-update"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Get-STVirusUpdate.ps1' 52
#Region '.\Public\Lock-STDomainGroup.ps1' 0
function Lock-STDomainGroup {
    <#
    .SYNOPSIS
    Locks out a domain group, preventing their admins from making changes to the domain group.
     
    .DESCRIPTION
    Locks out a domain group, preventing their admins from making changes to the domain group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    The target domain group Id
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Lock-STDomainGroup -Url $url -Token $token -GroupId 6
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Lock Domain Group")
        {
            $api = "$($Url)$($endpoint)/$($GroupId)/lock-out"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Lock-STDomainGroup.ps1' 58
#Region '.\Public\New-STAllowedIp.ps1' 0
function New-STAllowedIp {
    <#
    .SYNOPSIS
    Creates new allowed IP
     
    .DESCRIPTION
    Creates new allowed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be added
 
    .PARAMETER Mask
    Subnet mask. Allowed values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STAllowedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allows google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/ip/allow"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new allowed IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STAllowedIp.ps1' 83
#Region '.\Public\New-STAllowList.ps1' 0
function New-STAllowList {
    <#
    .SYNOPSIS
    Creates an allow-list entry
     
    .DESCRIPTION
    Creates an allow-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER Sender
    Sets the sender address for the specified allow-list. Required if domain isn't provided.
     
    .PARAMETER AllowedDomain
    Sets the domain for the specified allow-list. Required if sender isn't provided.
     
    .PARAMETER IncludeSubdomains
    Sets whether to include the subdomains of a domain.
     
    .PARAMETER Comment
    Sets the comment.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STAllowList -Url $url -Token $token -Domain "example.com" -Comment "Added via Powershell" -IncludeSubdmains
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DomainId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubdomains,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/allow-list"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Allow List")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/allow-list"
            }
            if($PSBoundParameters.ContainsKey("DomainId"))
            {
                $api = "$($Url)/restapi/domains/$($DomainId)/allow-list"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/allow-list"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $body["domain"] = "$($Domain)"
            }
            if($PSBoundParameters.ContainsKey("Sender"))
            {
                $body["sender"] = "$($Sender)"
            }
            if($PSBoundParameters.ContainsKey("IncludeSubdomains"))
            {
                $body["include_subdomains"] = "$($IncludeSubdomains)"
            }
            $body["comment"] = $Comment

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $($_|convertfrom-json -Depth 99)
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STAllowList.ps1' 116
#Region '.\Public\New-STArcSigningKey.ps1' 0
function New-STArcSigningKey {
    <#
    .SYNOPSIS
    Creates or generates a new signing key for ARC signing.
     
    .DESCRIPTION
    Creates or generates a new signing key for ARC signing.
     
    .PARAMETER Url
    Base url with Selector or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Selector
    Sets the selector for the ARC key.
 
    .PARAMETER PrivateKey
    Allows providing the private key of an already generated Signing key. If a new one is to be generated, pass in generate.
    Default 'generate'
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STArcSigningKey -Url $url -Token $token -Selector "arc-20190829"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Selector,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$PrivateKey = "generate"

    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc/keys"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"generates a new signing key for ARC signing")
        {
            $api = "$($Url)$($endpoint)/$($Selector)/dkim"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                selector = "$($Selector)"
                privatekey = "$($PrivateKey)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STArcSigningKey.ps1' 69
#Region '.\Public\New-STAuthorizationToken.ps1' 0
function New-STAuthorizationToken{
    <#
    .SYNOPSIS
    Generates a new authorization token for the user.
     
    .DESCRIPTION
    Generates a new authorization token for the user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Credential
    PSCredential for the target user
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>$creds = [pscredential]::new('user@domain',$(Convertto-Securestring -string "mypass" -AsPlainText -Force))
    PS>New-STAuthorizationToken -Url $url -Token $token -Credential $creds
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [pscredential]$Credential
    )
    Begin {
        $endpoint = "/restapi/auth/tokens"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new authorization token")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                email = "$($Credential.UserName)"
                password = "$($Credential.GetNetworkCredential().Password)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STAuthorizationToken.ps1' 63
#Region '.\Public\New-STBlockedIp.ps1' 0
function New-STBlockedIp {
    <#
    .SYNOPSIS
    Creates new Blocked IP
     
    .DESCRIPTION
    Creates new Blocked IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STBlockedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allows google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/ip/block"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Blocked IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STBlockedIp.ps1' 83
#Region '.\Public\New-STBlockList.ps1' 0
function New-STBlockList {
    <#
    .SYNOPSIS
    Creates an block-list entry
     
    .DESCRIPTION
    Creates an block-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER Sender
    Sets the sender address for the specified block-list. Required if domain isn't provided.
     
    .PARAMETER blockedDomain
    Sets the domain for the specified block-list. Required if sender isn't provided.
     
    .PARAMETER IncludeSubdomains
    Sets whether to include the subdomains of a domain.
     
    .PARAMETER Comment
    Sets the comment.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STBlockList -Url $url -Token $token -Domain "example.com" -Sender "sender@example.com" -Comment "Added via Powershell" -IncludeSubdmains
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubdomains,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/block-list"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new block List")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/block-list"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/block-list"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/block-list"
            }
            if($PSBoundParameters.ContainsKey("Sender"))
            {
                $body["sender"] = "$($Sender)"
            }
            if($PSBoundParameters.ContainsKey("IncludeSubdomains"))
            {
                $body["include_subdomains"] = "$($IncludeSubdomains)"
            }
            $body["comment"] = $Comment

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STBlockList.ps1' 111
#Region '.\Public\New-STDkimBypassedIp.ps1' 0
function New-STDkimBypassedIp {
    <#
    .SYNOPSIS
    Adds a new IP for Dkim Exemption
     
    .DESCRIPTION
    Adds a new IP for Dkim Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STDkimBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Dkim Bypass IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STDkimBypassedIp.ps1' 83
#Region '.\Public\New-STDkimKey.ps1' 0
function New-STDkimKey {
    <#
    .SYNOPSIS
    Generate a DKIM key.
     
    .DESCRIPTION
    Generate a DKIM key.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STDkimKey -Url $url -Token $token -Domain "example.com"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain

    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new DKIM key")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/dkim"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                selector = "$($Domain)"
                privatekey = "generate"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STDkimKey.ps1' 63
#Region '.\Public\New-STDmarcBypassedIp.ps1' 0
function New-STDmarcBypassedIp {
    <#
    .SYNOPSIS
    Adds a new IP for Dmarc Exemption
     
    .DESCRIPTION
    Adds a new IP for Dmarc Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STDmarcBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Dmarc Bypass IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STDmarcBypassedIp.ps1' 83
#Region '.\Public\New-STDomain.ps1' 0
function New-STDomain {
    <#
    .SYNOPSIS
    Creates a domain
     
    .DESCRIPTION
    Creates a domain
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
 
    .PARAMETER DestinationServer
    The server to look up recipient verification against.
 
    .PARAMETER Port
    The port to test against. On Exchange 2013 or newer, this will generally need to be 2525, and for every other server type will usually be the same as your SMTP port. Default 2525
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STDomain -Url $url -Token $token -Domain "example.com" -DestinationServer "ES01.domain.com" -Port 2525
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationServer,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Port = 2525

    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Domain")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/domains"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                domain = "$($Domain)"
                destination = "$($DestinationServer)"
                rv_type = "dynamic"
                "dynamic" = @{
                    dynamic_server = "$($DestinationServer)"
                    dynamic_port = "$($port)"
                }
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STDomain.ps1' 87
#Region '.\Public\New-STDomainGroup.ps1' 0
function New-STDomainGroup {
    <#
    .SYNOPSIS
    Creates a new Domain Group
     
    .DESCRIPTION
    Creates a new Domain Group
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Name
    The name of the domain group
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STDomainGroup -Url $url -Token $token -Name "MyGroup"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Name
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Domain Group")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                name = "$($Name)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STDomainGroup.ps1' 61
#Region '.\Public\New-STGeoblockingExemption.ps1' 0
function New-STGeoblockingExemption {
    <#
    .SYNOPSIS
    Creates a geoblocking sender exemption for global, domain group, domain or user.
     
    .DESCRIPTION
    Creates a geoblocking sender exemption for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER DomainId
    The ID of the domain.
     
    .PARAMETER UserId
    The ID of the user.
     
    .PARAMETER Comment
    Sets the comment.
 
    Size range: ..250
     
    .PARAMETER Domain
    The sender domain address to exclude from geo-blocking checks. Required if neither email nor ip is provided.
     
    .PARAMETER Email
    The sender email address to exclude from geo-blocking checks. Required if neither domain nor ip is provided.
     
    .PARAMETER IpAddress
    The sender ip address to exclude from geo-blocking checks. Required if neither domain nor email is provided.
     
    .PARAMETER IncludeSubDomain
    Sets whether to include the IncludeSubDomains of the specified domain.
 
    Default value: false
     
    .PARAMETER Mask
    The sender subnet mask to exclude from geo blocking checks. This is in CIDR notation.
    Default value: 32
    Size range: 8..32
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STGeoblockingExemption -Url $url -Token $token -Domain 'example.com' -IncludeSubDomain
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DomainId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain = $(if(-not ($Email) -and -not ($IpAddress)){throw "The parameter 'Domain' is mandatory when 'Email' or 'IpAddress' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Email = $(if(-not ($Domain) -and -not ($IpAddress)){throw "The parameter 'Email' is mandatory when 'Domain' or 'IpAddress' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$IpAddress = $(if(-not ($Domain) -and -not ($Email)){throw "The parameter 'IpAddress' is mandatory when 'Domain' or 'Email' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,32)]
        [string]$Mask = 32
    )
    Begin {
        $endpoint = "/restapi/geo-exemptions"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Geoblocking Exemption")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            if($PSBoundParameters.containskey("GroupId"))
            {
                $api = "$($Url)/domain-groups/$($GroupId)/geo-exemptions"
            }
            if($PSBoundParameters.containskey("Domain"))
            {
                $api = "$($Url)/domains/$($Domain)/geo-exemptions"
            }
            if($PSBoundParameters.containskey("UserId"))
            {
                $api = "$($Url)/users/$($UserId)/geo-exemptions"
            }
            if($PSBoundParameters.containskey("Comment"))
            {
                $body["comment"] = $Comment
            }
            if($PSBoundParameters.containskey("Domain"))
            {
                $body["domain"] = $Domain
            }
            if($PSBoundParameters.containskey("Email"))
            {
                $body["email"] = $Email
            }
            if($PSBoundParameters.containskey("IpAddress"))
            {
                $body["ip"] = $($IpAddress)
            }
            if($PSBoundParameters.containskey("IncludeSubDomain"))
            {
                $body["IncludeSubDomains"] = $IncludeSubDomain
            }
            if($PSBoundParameters.containskey("Mask"))
            {
                $body["mask"] = $Mask
            }
            try {
                $temp = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body | ConvertTo-Json -Depth 99) -ErrorAction Stop
                $Result += $temp.data
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STGeoblockingExemption.ps1' 145
#Region '.\Public\New-STGeoblockingRule.ps1' 0
function New-STGeoblockingRule {
    <#
    .SYNOPSIS
    Creates a geoblocking rule for global, domain group, domain or user.
     
    .DESCRIPTION
    Creates a geoblocking rule for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user
     
    .PARAMETER CountryIso
    The 2 digit ISO country code.
 
    .PARAMETER Geoblock
    Sets whether to block emails from a specified country.
     
    .PARAMETER Comment
    Sets the comment.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STGeoblockingRule -Url $url -Token $token -CountryIso US -Geoblock -Comment "Block US Global"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet([CountryIsos])]
        [string]$CountryIso,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Geoblock,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/geo-rules"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Geoblocking Rule")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/geo-rules"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/geo-rules"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/geo-rules"
            }
            if($PSBoundParameters.ContainsKey("CountryIso"))
            {
                $body["iso"] = "$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("Geoblock"))
            {
                $body["geoblock"] = $($Geoblock)
            }
            else
            {
                $body["geoblock"] = $false
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STGeoblockingRule.ps1' 118
#Region '.\Public\New-STLetsEncryptCert.ps1' 0
function New-STLetsEncryptCert {
    <#
    .SYNOPSIS
    Begins a queue job that requests a new LetsEncrypt certificate and sets up all the processes that need to use it, to use it. The Common Name of the certificate is defined by the hostname of the system.
     
    .DESCRIPTION
    Begins a queue job that requests a new LetsEncrypt certificate and sets up all the processes that need to use it, to use it. The Common Name of the certificate is defined by the hostname of the system.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STLetsEncryptCert -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DistinguishedName,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(2,2)]
        [string]$Country,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(2,2)]
        [string]$State,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Locality,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$OrganizationName,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$OrganizationUnitName,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$EmailAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string[]]$SubjectAlternativeNames

    )
    Begin {
        $endpoint = "/restapi/ip/allow"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"New Let's Encrypt Certificate")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("DistinguishedName"))
            {
                $body["distinguished_name"] = $DistinguishedName
            }
            if($PSBoundParameters.containskey("Country"))
            {
                $body["country"] = $Country
            }
            if($PSBoundParameters.containskey("State"))
            {
                $body["state"] = $State
            }
            if($PSBoundParameters.containskey("Locality"))
            {
                $body["locality"] = $Locality
            }
            if($PSBoundParameters.containskey("OrganizationName"))
            {
                $body["organization_name"] = $OrganizationName
            }
            if($PSBoundParameters.containskey("OrganizationUnitName"))
            {
                $body["organization_unit_name"] = $OrganizationUnitName
            }
            if($PSBoundParameters.containskey("EmailAddress"))
            {
                $body["email_address"] = $EmailAddress
            }
            if($PSBoundParameters.containskey("SubjectAlternativeNames"))
            {
                $body["subject_alternative_names"] = $SubjectAlternativeNames
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STLetsEncryptCert.ps1' 114
#Region '.\Public\New-STPattern.ps1' 0
function New-STPattern {
    <#
    .SYNOPSIS
    Creates a new pattern filter
     
    .DESCRIPTION
    Creates a new pattern filter
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
    .PARAMETER Pattern
    The pattern for the pattern filter.
     
    .PARAMETER Type
    The way to utilize the pattern. Available filter types:
 
    regex: Pattern is a Regular Expression
    contains: Pattern exists somewhere in body/header.
    startswith: Body/header starts with pattern.
    endswith: Body/header ends with pattern.
    exact: Body/header exactly matches pattern.
    anyword: Pattern is a string of words separated by spaces, and any word in that list can exist in body/header.
    meta: Advanced matching for creating meta rules. RULE_<ID> is how you match against another Pattern Filter (said Pattern Filter must be in test mode), or you can specify the name of the rule you wish to match directly. Use && for AND and || for OR, you may wrap rules in parenthesis to match a grouping.
 
    Default value: regex
 
    Allowed values: regex, contains, startswith, endswith, exact, anyword, meta
     
    .PARAMETER ApplyBody
    Apply the pattern filter to the body. You must set either this or apply_headers to true, or both.
 
    Default value: false
     
    .PARAMETER RawBody
    If apply_body is true, then this makes the pattern filter trigger against the raw body of the email, allowing it to trigger on HTML tags and the like.
 
    Default value: false
     
    .PARAMETER ApplyHeaders
    Apply the pattern filter to the body. You must set either this or apply_body to true, or both.
 
    Default value: false
     
    .PARAMETER Headers
    If apply_headers is true, the this determines what headers to trigger on in the email.
 
    Default value: ALL
     
    .PARAMETER Score
    This is the score to add to an email if the pattern filter triggers. Setting this to 0 puts the pattern filter into test mode. Setting this above 0 classifies it as a blocked pattern. Setting this below 0 classifies it as an allowed pattern.
 
    Default value: 0
 
    Size range: -100 to 100
     
    .PARAMETER DisableRule
    Set the pattern filter to disabled or not.
 
    Default value: false
     
    .PARAMETER Comment
    The comment for the pattern filter.
 
    Default value: Added by API
 
    Size range: ..250
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STPattern -Url $url -Token $token -Type Regex -Pattern '[Mm]alicious\s[Aa]ctivity'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Pattern,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("regex","contains","startswith","endswith","exact","anyword","meta")]
        [string]$Type = "regex",
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ApplyBody,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$RawBody,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ApplyHeaders,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string[]]$Headers = "ALL",
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(-100,100)]
        [int]$Score = 0,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$DisableRule,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/patterns"
        [array]$Result = @()
        [hashtable]$body = @{
            pattern = "$($Pattern)"
            type = "$($Type)"
            headers = @($Headers)
            score = $Score
            comment = $Comment
        }
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new pattern filter")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/patterns"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/patterns"
            }
            if($PSBoundParameters.containskey("ApplyBody"))
            {
                $body["apply_body"] = $ApplyBody
            }
            if($PSBoundParameters.containskey("RawBody"))
            {
                $body["rawbody"] = $RawBody
            }
            if($PSBoundParameters.containskey("ApplyHeaders"))
            {
                $body["apply_headers"] = $ApplyHeaders
            }
            if($PSBoundParameters.containskey("DisableRule"))
            {
                $body["disable_rule"] = $DisableRule
            }
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STPattern.ps1' 172
#Region '.\Public\New-STRateControlPolicy.ps1' 0
function New-STRateControlPolicy {
    <#
    .SYNOPSIS
    Creates a new Rate Control Policy
     
    .DESCRIPTION
    Creates a new Rate Control Policy
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Name
    The name of the Rate Control Policy.
 
    Size range: ..250
     
    .PARAMETER Enabled
    Whether or not the Rate Control Policy is enabled
     
    .PARAMETER Source
    What kind of source to be looking at.
 
    any: Tracks emails from any sources.
    internal: Tracks emails from Trusted Networks.
    external: Tracks emails that aren't from Trusted Networks.
    domain: Must provide source_domain to specify what domain to track.
    email: Must provide source_email to specify what email to track.
    cidr: Must provide source_cidr to specify what CIDR to track.
 
    Allowed values: any, internal, external, domain, email, cidr
     
    .PARAMETER SourceEmail
    The email to track in the source. Required if source is set to email
     
    .PARAMETER SourceDomain
    he domain to track in the source. Required if source is set to domain
     
    .PARAMETER SourceCidr
    The CIDR to track in the source. Required if source is set to cidr.
     
    .PARAMETER Destination
    What kind of destination to follow.
 
    any: Tracks emails to any destination.
    domain: Must provide the destination_domainto specify what email to track.
    email: Must provide the destination_emailto specify what email to track.
 
    Allowed values: any, domain, email
     
    .PARAMETER DestinationEmail
    The email destination to track. Required if destination is set to email
     
    .PARAMETER DestinationDomain
    The domain destination to track. Required if destination is set to domain
     
    .PARAMETER Track
    What type of thing to count for tracking rate controls.
 
    Allowed values: ip, sender, email, sender, domain, recipient, email, recipient, domain
     
    .PARAMETER Bitmask
    The CIDR bitmask to track. Required if track is set to ip.
 
    Size range: 8..32
     
    .PARAMETER StopProcessing
    Whether to stop processing more policies after this policy has been hit
     
    .PARAMETER Priority
    The priority of the policy. Lower numbers represent higher priority. Priority 1 will be the first checked.
 
    Size range: 1..32767
     
    .PARAMETER RateLimit
    What to rate limit based off of. Either the Message Count of the Cumulative size of the messages (in kB).
 
    Allowed values: MessageCount, MessageCumulativeSize
     
    .PARAMETER LimitCount
    The number of mails to hit the limit before executing the action.
 
    Size range: 1..
     
    .PARAMETER Period
    The period of time to listen to the tracking to detect exceeded limits. This is over a rolling period of time. This is over the period of time in period_unit.
 
    Size range: 1..
     
    .PARAMETER PeriodUnit
    The unit the period should be tracked in.
 
    Allowed values: second, minute, hour
     
    .PARAMETER Action
    Whether to defer (4XX response) mails that exceed the rate limit, or reject (5XX response) them outright.
 
    Allowed values: DEFER, REJECT
     
    .PARAMETER SmtpResponse
    The text/response to go alongside the action.
 
    Size range: ..250
     
    .PARAMETER NotifyAdmin
    Whether to notify an administrator when the rate limit has been exceeded
     
    .PARAMETER NotifyAddress
    The address to send notifications to. Required if notify_admin is true
     
    .PARAMETER Comment
    A comment to associate with the policy.
 
    Default value: Added by API
 
    Size range: ..250
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS> $splat = @{
        Url = $url
        Token = $token
        Name= "Example"
        Enabled = $true
        Source= "any"
        Destination= "any"
        Track= "sender"
        StopProcessing = $true
        Priority = 3
        RateLimit = "MessageCount"
        LimitCount = 50
        Period = 30
        PeriodUnit = "minute"
        Action = "REJECT"
        SmtpResponse = "An Example policy"
        NotifyAdmin = $true
        NotifyAddress = "admin@example.com"
    }
    PS>New-STRateControlPolicy @splat
    #>

    
    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Name,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("any", "internal", "external", "domain", "email", "cidr")]
        [string]$Source,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceEmail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceCidr,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("any", "domain", "email")]
        [string]$Destination,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationEmail,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationDomain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("ip", "sender", "email", "sender", "domain", "recipient", "email", "recipient", "domain")]
        [string]$Track,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,32)]
        [string]$Bitmask,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [switch]$StopProcessing,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(1,32767)]
        [int]$Priority,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("MessageCount", "MessageCumulativeSize")]
        [string]$RateLimit,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({if(-not ($_ -gt 0)){throw "Limit must be > 0"}return $true})]
        [int]$LimitCount,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({if(-not ($_ -gt 0)){throw "Period must be > 0"}return $true})]
        [int]$Period,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("second", "minute", "hour")]
        [string]$PeriodUnit,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("DEFER", "REJECT")]
        [string]$Action,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$SmtpResponse,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$NotifyAdmin,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$NotifyAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment = "Added by API"

    )
    Begin {
        $endpoint = "/restapi/rate-controls/policies"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Rate Control Policy")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                name = $Name
                enabled = $Enabled
                source = $Source
                destination = $Destination
                track = $Track
                stop_processing = $StopProcessing
                priority = $Priority
                rate_limit = $RateLimit
                limit_count = $LimitCount
                period = $Period
                period_unit = $PeriodUnit
                action = $Action
                smtp_response = $SmtpResponse
                notify_admin = $NotifyAdmin
                comment = $Comment
            }
            if($PSBoundParameters.ContainsKey("SourceEmail"))
            {
                $body["source_email"] = $SourceEmail
            }
            if($PSBoundParameters.ContainsKey("SourceDomain"))
            {
                $body["source_domain"] = $SourceDomain
            }
            if($PSBoundParameters.ContainsKey("SourceCidr"))
            {
                $body["source_cidr"] = $SourceCidr
            }
            if($PSBoundParameters.ContainsKey("DestinationEmail"))
            {
                $body["destination_email"] = $DestinationEmail
            }
            if($PSBoundParameters.ContainsKey("DestinationDomain"))
            {
                $body["destination_domain"] = $DestinationDomain
            }
            if($PSBoundParameters.ContainsKey("Bitmask"))
            {
                $body["bitmask"] = $Bitmask
            }
            if($PSBoundParameters.ContainsKey("NotifyAddress"))
            {
                $body["notify_address"] = $NotifyAddress
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STRateControlPolicy.ps1' 280
#Region '.\Public\New-STRblBypassedIp.ps1' 0
function New-STRblBypassedIp {
    <#
    .SYNOPSIS
    Creates new Blocked IP
     
    .DESCRIPTION
    Creates new Blocked IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STRblBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/rbl/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new RBL Bypass IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STRblBypassedIp.ps1' 83
#Region '.\Public\New-STSpfBypassedIp.ps1' 0
function New-STSpfBypassedIp {
    <#
    .SYNOPSIS
    Adds a new IP for SPF Exemption
     
    .DESCRIPTION
    Adds a new IP for SPF Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STSpfBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new SPF Bypass IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STSpfBypassedIp.ps1' 83
#Region '.\Public\New-STTlsPolicy.ps1' 0
function New-STTlsPolicy {
    <#
    .SYNOPSIS
    Add a specific TLS Exception Policies. This is a per-recipient TLS Policy.
     
    .DESCRIPTION
    Add a specific TLS Exception Policies. This is a per-recipient TLS Policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .PARAMETER SubDomain
    Whether to include subdomains as well.
 
    Default value: false
 
    .PARAMETER Policy
    What TLS policy to set.
 
    Allowed values: none, may, encrypt, verify
 
    .PARAMETER Protocols
    The protocols to use if the policy is set to encrypt or verify.
 
    Allowed values: SSLv2, SSLv3, !SSLv2:!SSLv3, SSLv2:SSLv3, SSLv3:TLSv1, SSLv2:SSLv3:TLSv1
 
    .PARAMETER Comment
    The comment for the policy.
 
    Default value: Added by API
 
    Size range: ..250
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STTlsPolicy -Url $url -Token $token -Domain "example.com" -Policy "encrypt" -Protocols "SSLv3:TLSv1" -Comment "Added by API"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SubDomain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("none","may","encrypt","verify")]
        [string]$Policy,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("SSLv2", "SSLv3", "!SSLv2:!SSLv3", "SSLv2:SSLv3", "SSLv3:TLSv1", "SSLv2:SSLv3:TLSv1")]
        [string]$Protocols = $(if($Policy -imatch 'encrypt|verify'){throw "when 'Policy' is set to 'encrypt' or 'verify', the Protocols parameter is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Add TLS Policy")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/dkim"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                domain = "$($Domain)"
                policy = $Policy
            }
            if($PSBoundParameters.ContainsKey("SubDomain"))
            {
                $body["subdomain"] = $SubDomain
            }
            if($PSBoundParameters.ContainsKey("Protocols"))
            {
                $body["protocols"] = $Protocols
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STTlsPolicy.ps1' 107
#Region '.\Public\New-STTrustedNetwork.ps1' 0
function New-STTrustedNetwork {
    <#
    .SYNOPSIS
    Add a Trusted Network.
     
    .DESCRIPTION
    Add a Trusted Network.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STTrustedNetwork -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new Trusted Network")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ip = "$($IpAddress)"
                mask = "$($Mask)"
                comment = "$Comment"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STTrustedNetwork.ps1' 83
#Region '.\Public\New-STUser.ps1' 0
function New-STUser {
    <#
    .SYNOPSIS
    Creates a new user
     
    .DESCRIPTION
    Creates a new user
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER EmailAddress
    New user email address
     
    .PARAMETER RoleId
    Role id the new user will receive
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STUser -Url $url -Token $token -Domain "example.com" -EmailAddress "user@example.com"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '^(?:(?!.*?[.]{2})[a-zA-Z0-9](?:[a-zA-Z0-9.+!%-]{1,64}|)|\"[a-zA-Z0-9.+!% -]{1,64}\")@[a-zA-Z0-9][a-zA-Z0-9.-]+(.[a-z]{2,}|.[0-9]{1,})$'))
            {
                throw "Invalid Email address"
            }
            return $true
        })]
        [string]$EmailAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$RoleId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [securestring]$Password
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new User")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/users"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/users"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                email = $EmailAddress
            }
            if($PSBoundParameters.ContainsKey("RoleId"))
            {
                $body["id"] = $RoleId
            }
            if($PSBoundParameters.ContainsKey("Password"))
            {
                $body["password"] = $($Password | ConvertFrom-SecureString -AsPlainText)
                $body["confim_password"] = $($Password | ConvertFrom-SecureString -AsPlainText)
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\New-STUser.ps1' 102
#Region '.\Public\Remove-STAllowedIp.ps1' 0
function Remove-STAllowedIp {
    <#
    .SYNOPSIS
    Removes an Allowed IP
     
    .DESCRIPTION
    Removes an Allowed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER AllowedIpId
    Target Allowed IP
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STAllowedIp -Url $url -Token $token -AllowedIpId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$AllowedIpId

    )
    Begin {
        $endpoint = "/restapi/ip/allow"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove Allowed IP")
        {
            $api = "$($Url)$($endpoint)/$($AllowedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STAllowedIp.ps1' 61
#Region '.\Public\Remove-STAllowList.ps1' 0
function Remove-STAllowList {
    <#
    .SYNOPSIS
    Remove an allow-list entry
     
    .DESCRIPTION
    Remove an allow-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER AllowListId
    Target Allow List ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STAllowList -Url $url -Token $token -AllowListId 45
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$AllowListId
    )
    Begin {
        $endpoint = "/restapi/allow-list"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove Allow List")
        {
            $api = "$($Url)$($endpoint)/$($AllowListId)"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STAllowList.ps1' 60
#Region '.\Public\Remove-STArcKey.ps1' 0
function Remove-STArcKey {
    <#
    .SYNOPSIS
    Deletes one or more ARC signing key(s).
     
    .DESCRIPTION
    Deletes one or more ARC signing key(s).
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER ArcKeyId
    Target ARC Key
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STArcKey -Url $url -Token $token -ArcKeyId 3
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$ArcKeyId

    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc/keys"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($ArcKeyId),"Remove ARC Key")
        {
            $api = "$($Url)$($endpoint)/$($ArcKeyId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STArcKey.ps1' 59
#Region '.\Public\Remove-STBlockedIp.ps1' 0
function Remove-STBlockedIp {
    <#
    .SYNOPSIS
    Removes an Blocked IP
     
    .DESCRIPTION
    Removes an Blocked IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER BlockedIpId
    Target Blocked IP
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STBlockedIp -Url $url -Token $token -BlockedIpId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$BlockedIpId

    )
    Begin {
        $endpoint = "/restapi/ip/block"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove Blocked IP")
        {
            $api = "$($Url)$($endpoint)/$($BlockedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STBlockedIp.ps1' 61
#Region '.\Public\Remove-STBlockList.ps1' 0
function Remove-STBlockList {
    <#
    .SYNOPSIS
    Remove an Block-list entry
     
    .DESCRIPTION
    Remove an Block-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER BlockListId
    Target Block List ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STBlockList -Url $url -Token $token -BlockListId 45
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$BlockListId
    )
    Begin {
        $endpoint = "/restapi/block-list"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove Block List")
        {
            $api = "$($Url)$($endpoint)/$($BlockListId)"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STBlockList.ps1' 60
#Region '.\Public\Remove-STDkim.ps1' 0
function Remove-STDkim {
    <#
    .SYNOPSIS
    Delete DKIM.
     
    .DESCRIPTION
    Delete DKIM.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER DkimId
    The ID of the DKIM
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STDkim -Url $url -Token $token -Domain "example.com" -DkimId 3
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DkimId

    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Delete Domain DKIM")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/dkim/$($DkimId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STDkim.ps1' 65
#Region '.\Public\Remove-STDkimBypassedIp.ps1' 0
function Remove-STDkimBypassedIp {
    <#
    .SYNOPSIS
    Deletes one or more IP(s) from Dkim Exemption
     
    .DESCRIPTION
    Deletes one or more IP(s) from Dkim Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER DkimBypassedIpId
    Target IP Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STDkimBypassedIp -Url $url -Token $token -DkimBypassedIpId 43
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$DkimBypassedIpId

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($DkimBypassedIpId),"Remove Dkim Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($DkimBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STDkimBypassedIp.ps1' 60
#Region '.\Public\Remove-STDmarcBypassedIp.ps1' 0
function Remove-STDmarcBypassedIp {
    <#
    .SYNOPSIS
    Deletes one or more IP(s) from Dmarc Exemption
     
    .DESCRIPTION
    Deletes one or more IP(s) from Dmarc Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER DmarcBypassedIpId
    Target IP Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STDmarcBypassedIp -Url $url -Token $token -DmarcBypassedIpId 23
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$DmarcBypassedIpId

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($DmarcBypassedIpId),"Remove Dmarc Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($DmarcBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STDmarcBypassedIp.ps1' 60
#Region '.\Public\Remove-STDomain.ps1' 0
function Remove-STDomain {
    <#
    .SYNOPSIS
    Updates a domain.
     
    .DESCRIPTION
    Updates a domain.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STDomain -Url $url -Token $token -Domain "example.com" -DkimId 525
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId

    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Delete Domain")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/domains"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STDomain.ps1' 68
#Region '.\Public\Remove-STDomainGroup.ps1' 0
function Remove-STDomainGroup {
    <#
    .SYNOPSIS
    Updates specified Domain Group.
     
    .DESCRIPTION
    Updates specified Domain Group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER GroupId
    Target Group Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STDomainGroup -Url $url -Token $token -GroupId 5
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Domain Group")
        {
            $api = "$($Url)$($endpoint)/$($GroupId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STDomainGroup.ps1' 59
#Region '.\Public\Remove-STGeoblockingExemption.ps1' 0
function Remove-STGeoblockingExemption {
    <#
    .SYNOPSIS
    Removes geoblocking Exemption for global, domain group, domain or user.
     
    .DESCRIPTION
    Removes geoblocking Exemption for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user
 
    .PARAMETER ExemptionId
    Target Exemption ID
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STGeoblockingRule -Url $url -Token $token -ExemptionId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DomainId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$ExemptionId

    )
    Begin {
        $endpoint = "/restapi/geo-exemptions"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($ExemptionId),"Remove Geoblocking Exemption")
        {
            $api = "$($Url)$($endpoint)/$($ExemptionId)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/geo-exemptions/$($ExemptionId)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/geo-exemptions/$($ExemptionId)"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/geo-exemptions/$($ExemptionId)"
            }

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STGeoblockingExemption.ps1' 88
#Region '.\Public\Remove-STGeoblockingRule.ps1' 0
function Remove-STGeoblockingRule {
    <#
    .SYNOPSIS
    Remove geoblocking rule for global, domain group, domain or user.
     
    .DESCRIPTION
    Remove geoblocking rule for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user
     
    .PARAMETER CountryIso
    The 2 digit ISO country code.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STGeoblockingRule -Url $url -Token $token -CountryIso US
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STGeoblockingRule -Url $url -Token $token -CountryIso US -GroupId 5
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet([CountryIsos])]
        [string]$CountryIso

    )
    Begin {
        $endpoint = "/restapi/geo-rules"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($CountryIso),"Remove Geoblocking Rule")
        {
            $api = "$($Url)$($endpoint)/$($CountryIso)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/geo-rules/$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/geo-rules/$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/geo-rules/$($CountryIso)"
            }

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STGeoblockingRule.ps1' 93
#Region '.\Public\Remove-STOutboundRelayHostname.ps1' 0
function Remove-STOutboundRelayHostname {
    <#
    .SYNOPSIS
    Removes a Hostname
     
    .DESCRIPTION
    Removes a Hostname
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Hostname
    Current Hostname
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STOutboundRelayHostname -Url $url -Token $token -Hostname 'mail.example.com'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Hostname

    )
    Begin {
        $endpoint = "/restapi/outbound/hostnames"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove Outbound Relay Hostname")
        {
            $api = "$($Url)$($endpoint)/$($Hostname)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STOutboundRelayHostname.ps1' 59
#Region '.\Public\Remove-STPattern.ps1' 0
function Remove-STPattern {
    <#
    .SYNOPSIS
    Removes a pattern filter
     
    .DESCRIPTION
    Removes a pattern filter
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
     
    .PARAMETER Pattern
    The pattern for the pattern filter.
     
    .PARAMETER Type
    The way to utilize the pattern. Available filter types:
 
    regex: Pattern is a Regular Expression
    contains: Pattern exists somewhere in body/header.
    startswith: Body/header starts with pattern.
    endswith: Body/header ends with pattern.
    exact: Body/header exactly matches pattern.
    anyword: Pattern is a string of words separated by spaces, and any word in that list can exist in body/header.
    meta: Advanced matching for creating meta rules. RULE_<ID> is how you match against another Pattern Filter (said Pattern Filter must be in test mode), or you can specify the name of the rule you wish to match directly. Use && for AND and || for OR, you may wrap rules in parenthesis to match a grouping.
 
    Default value: regex
 
    Allowed values: regex, contains, startswith, endswith, exact, anyword, meta
     
    .PARAMETER ApplyBody
    Apply the pattern filter to the body. You must set either this or apply_headers to true, or both.
 
    Default value: false
     
    .PARAMETER RawBody
    If apply_body is true, then this makes the pattern filter trigger against the raw body of the email, allowing it to trigger on HTML tags and the like.
 
    Default value: false
     
    .PARAMETER ApplyHeaders
    Apply the pattern filter to the body. You must set either this or apply_body to true, or both.
 
    Default value: false
     
    .PARAMETER Headers
    If apply_headers is true, the this determines what headers to trigger on in the email.
 
    Default value: ALL
     
    .PARAMETER Score
    This is the score to add to an email if the pattern filter triggers. Setting this to 0 puts the pattern filter into test mode. Setting this above 0 classifies it as a blocked pattern. Setting this below 0 classifies it as an allowed pattern.
 
    Default value: 0
 
    Size range: -100 to 100
     
    .PARAMETER DisableRule
    Set the pattern filter to disabled or not.
 
    Default value: false
     
    .PARAMETER Comment
    The comment for the pattern filter.
 
    Default value: Added by API
 
    Size range: ..250
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STPattern -Url $url -Token $token -PatternId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$PatternId
    )
    Begin {
        $endpoint = "/restapi/patterns"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new pattern filter")
        {
            $api = "$($Url)$($endpoint)/$($PatternId)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/patterns/$($PatternId)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/patterns/$($PatternId)"
            }
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STPattern.ps1' 131
#Region '.\Public\Remove-STQuarantinedEmail.ps1' 0
function Remove-STQuarantinedEmail {
    <#
    .SYNOPSIS
    Remove an Block-list entry
     
    .DESCRIPTION
    Remove an Block-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER QuarantineId
    Target Block List ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STQuarantinedEmail -Url $url -Token $token -QuarantineId "0c7fuE5s87wJ"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$QuarantineId
    )
    Begin {
        $endpoint = "/restapi/quarantine"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove quarantined email")
        {
            $api = "$($Url)$($endpoint)/$($QuarantineId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STQuarantinedEmail.ps1' 58
#Region '.\Public\Remove-STRateControlPolicy.ps1' 0
function Remove-STRateControlPolicy {
    <#
    .SYNOPSIS
    Deletes specified Rate Control Policy..
     
    .DESCRIPTION
    Deletes specified Rate Control Policy..
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER PolicyId
    Target Group Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STRateControlPolicy -Url $url -Token $token -PolicyId 6
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$PolicyId
    )
    Begin {
        $endpoint = "/restapi/rate-controls/policies"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($PolicyId,"Remove Rate Control Policy"))
        {
            
            $api = "$($Url)$($endpoint)/$($PolicyId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try {    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STRateControlPolicy.ps1' 60
#Region '.\Public\Remove-STRbl.ps1' 0
function Remove-STRbl {
    <#
    .SYNOPSIS
    Removes a RBL
     
    .DESCRIPTION
    Removes a RBL
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Rbl
    Current RBL
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STRbl -Url $url -Token $token -Rbl 'kitten.gbudb.net'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Rbl

    )
    Begin {
        $endpoint = "/restapi/rbl"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove RBL")
        {
            $api = "$($Url)$($endpoint)/$($Rbl)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STRbl.ps1' 59
#Region '.\Public\Remove-STRblBypassedIp.ps1' 0
function Remove-STRblBypassedIp {
    <#
    .SYNOPSIS
    Remove RBL Bypassed IP
     
    .DESCRIPTION
    Remove RBL Bypassed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER RblBypassedIpId
    Target Bypassed IP Id.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STRblBypassedIp -Url $url -Token $token -RblBypassedIpId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$RblBypassedIpId
    )
    Begin {
        $endpoint = "/restapi/rbl/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove RBL Bypassed IP")
        {
            $api = "$($Url)$($endpoint)/$($RblBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STRblBypassedIp.ps1' 59
#Region '.\Public\Remove-STSenderBasedSmarthost.ps1' 0
function Remove-STSenderBasedSmarthost {
    <#
    .SYNOPSIS
    Removes Sender Based Smarthost
     
    .DESCRIPTION
    Removes Sender Based Smarthost
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER SmarthostId
    Current SmarthostId
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STSenderBasedSmarthost -Url $url -Token $token -SmarthostId 5
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$SmarthostId

    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost/sender"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove SmarthostId")
        {
            $api = "$($Url)$($endpoint)/$($SmarthostId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STSenderBasedSmarthost.ps1' 59
#Region '.\Public\Remove-STServerWideSmarthost.ps1' 0
function Remove-STServerWideSmarthost {
    <#
    .SYNOPSIS
    Removes Server Wide Smarthost
     
    .DESCRIPTION
    Removes Server Wide Smarthost
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER SmarthostId
    Current SmarthostId
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STServerWideSmarthost -Url $url -Token $token -SmarthostId 5
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$SmarthostId

    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost/sender"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Remove SmarthostId")
        {
            $api = "$($Url)$($endpoint)/$($SmarthostId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STServerWideSmarthost.ps1' 59
#Region '.\Public\Remove-STSpfBypassedIp.ps1' 0
function Remove-STSpfBypassedIp {
    <#
    .SYNOPSIS
    Deletes one or more IP(s) from SPF Exemption
     
    .DESCRIPTION
    Deletes one or more IP(s) from SPF Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER SpfBypassedIpId
    Target IP Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STSpfBypassedIp -Url $url -Token $token -SpfBypassedIpId 23
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$SpfBypassedIpId

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/bypass"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($SpfBypassedIpId),"Remove SPF Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($SpfBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STSpfBypassedIp.ps1' 60
#Region '.\Public\Remove-STTlsPolicy.ps1' 0
function Remove-STTlsPolicy {
    <#
    .SYNOPSIS
    Removes a TlsPolicyId
     
    .DESCRIPTION
    Removes a TlsPolicyId
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER TlsPolicyId
    Current TlsPolicyId
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STTlsPolicy -Url $url -Token $token -TlsPolicyId 56
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$TlsPolicyId

    )
    Begin {
        $endpoint = "/restapi/outbound/tls"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($TlsPolicyId),"Remove TLS Policy")
        {
            $api = "$($Url)$($endpoint)/$($TlsPolicyId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STTlsPolicy.ps1' 59
#Region '.\Public\Remove-STTrustedNetwork.ps1' 0
function Remove-STTrustedNetworkId {
    <#
    .SYNOPSIS
    Delete a Trusted Network
     
    .DESCRIPTION
    Delete a Trusted Network
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER TrustedNetworkId
    Target Bypassed IP Id.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STTrustedNetworkId -Url $url -Token $token -TrustedNetworkIdId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$TrustedNetworkId
    )
    Begin {
        $endpoint = "/restapi/outbound/trusted"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Delete a Trusted Network")
        {
            $api = "$($Url)$($endpoint)/$($TrustedNetworkId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STTrustedNetwork.ps1' 59
#Region '.\Public\Remove-STUser.ps1' 0
function Remove-STUser {
    <#
    .SYNOPSIS
    Removes a user
     
    .DESCRIPTION
    Removes a user
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER Userid
    The ID that is to be deleted
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STUser -Url $url -Token $token -UserId 4
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Userid
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Userid),"Remove a User")
        {
            $api = "$($Url)$($endpoint)/$($Userid)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/users/$($Userid)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/users/$($Userid)"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STUser.ps1' 76
#Region '.\Public\Remove-STUserAliasEmail.ps1' 0
function Remove-STUserAliasEmail {
    <#
    .SYNOPSIS
    Remove alias
     
    .DESCRIPTION
    Remove alias
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER UserId
    Target user ID
     
    .PARAMETER EmailAddress
    Email to be deleted. If not specified all aliases are removed.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Remove-STUserAliasEmail -Url $url -Token $token -UserId 1234 -EmailAddress "alias@example.com"
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$'))
            {
                throw "Invalid Email address"
            }
            return $true
        })]
        [string]$EmailAddress
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Remove alias")
        {
            $api = "$($Url)$($endpoint)/$($UserId)/aliases"
            if($PSBoundParameters.ContainsKey("EmailAddress"))
            {
                $api = "$($Url)$($endpoint)/$($UserId)/aliases/$($EmailAddress)"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Remove-STUserAliasEmail.ps1' 75
#Region '.\Public\Request-STQuarantineReport.ps1' 0
function Request-STQuarantineReport {
    <#
    .SYNOPSIS
    Request a Quarantine Report for the Authorized user.
     
    .DESCRIPTION
    Request a Quarantine Report for the Authorized user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Request-STQuarantineReport -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/quarantine/report"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Request-STQuarantineReport.ps1' 52
#Region '.\Public\Reset-STDmarcReportingSetting.ps1' 0
function Reset-STDmarcReportingSetting {
    <#
    .SYNOPSIS
    Sets the DMARC reporting settings to default settings based on License
     
    .DESCRIPTION
    Sets the DMARC reporting settings to default settings based on License
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER DmarcBypassedIpId
    Target IP Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Reset-STDmarcReportingSetting -Url $url -Token $token -DmarcBypassedIpId 23
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/reporting"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($DmarcBypassedIpId),"Sets the DMARC reporting settings to default")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Reset-STDmarcReportingSetting.ps1' 58
#Region '.\Public\Reset-STUserPassword.ps1' 0
function Reset-STUserPassword{
    <#
    .SYNOPSIS
    Sets a new password for the Authenticated User.
     
    .DESCRIPTION
    Sets a new password for the Authenticated User.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Password
    Minimum length of the password: 10 characters
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>$creds = $(Convertto-Securestring -string "jfa9e0rj32irj0wjf0wedjf0((fj09J" -AsPlainText -Force)
    PS>Reset-STUserPassword -Url $url -Token $token -Password $creds
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($($_ | ConvertFrom-SecureString -AsPlainText).Length -lt 10)
            {
                throw "Password must be at least 10 characters. Current Length: $($($_ | ConvertFrom-SecureString -AsPlainText).Length)"
            }
            return $true
        })]
        [securestring]$Password
    )
    Begin {
        $endpoint = "/restapi/auth/password"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Set a new password for the Authenticated User"))
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                password = "$($Password | ConvertFrom-SecureString -AsPlainText)"
                new_password = "$($Password | ConvertFrom-SecureString -AsPlainText)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Reset-STUserPassword.ps1' 70
#Region '.\Public\Restore-STDomainGroup.ps1' 0
function Restore-STDomainGroup {
    <#
    .SYNOPSIS
    Reinstates a domain, undoing a suspension and lockout.
     
    .DESCRIPTION
    Reinstates a domain, undoing a suspension and lockout.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    Target Group Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Restore-STDomainGroup -Url $url -Token $token -GroupId 6
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Reinstates a domain, undoing a suspension and lockout."))
        {
            
            $api = "$($Url)$($endpoint)/$($GroupId)/reinstate"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try {    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Restore-STDomainGroup.ps1' 60
#Region '.\Public\Restore-STRevokedAuthorizationToken.ps1' 0
function Restore-STRevokedAuthorizationToken {
    <#
    .SYNOPSIS
    Unrevokes an authorization token
     
    .DESCRIPTION
    Unrevokes an authorization token
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER TokenId
    The Identifier of the token to be (un)revoked. If no identifier is provided, all tokens will be (un)revoked.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>$RevokedToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>Restore-STRevokedAuthorizationToken -Url $url -Token $token -TokenId $RevokedToken
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$TokenId
    )
    Begin {
        $endpoint = "/restapi/auth/tokens"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Unrevokes an authorization token"))
        {
            
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("TokenId"))
            {
                $api = "$($Url)$($endpoint)/$($TokenId)"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try {    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Restore-STRevokedAuthorizationToken.ps1' 65
#Region '.\Public\Revoke-STAuthorizationToken.ps1' 0
function Revoke-STAuthorizationToken {
    <#
    .SYNOPSIS
    Revokes an authorization token.
     
    .DESCRIPTION
    Revokes an authorization token.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER TokenId
    The Identifier of the token to be revoked. If no identifier is provided, all tokens will be revoked.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>$RevokedToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>Revoke-STAuthorizationToken -Url $url -Token $token -TokenId $RevokedToken
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$TokenId
    )
    Begin {
        $endpoint = "/restapi/auth/tokens"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Revokes an authorization token"))
        {
            
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("TokenId"))
            {
                $api = "$($Url)$($endpoint)/$($TokenId)"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try {    
                $Result = Invoke-RestMethod -Method Delete -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Revoke-STAuthorizationToken.ps1' 65
#Region '.\Public\Set-STArcKey.ps1' 0
function Set-STArcKey {
    <#
    .SYNOPSIS
    Set the DMARC reporting settings
     
    .DESCRIPTION
    Set the DMARC reporting settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER ArcKeyId
    Target ARC key id
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STArcKey -Url $url -Token $token -ArcKeyId 234
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$ArcKeyId
    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set ARC Key to use for ARC signing")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                id = $($ArcKeyId)
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STArcKey.ps1' 63
#Region '.\Public\Set-STClientCertificate.ps1' 0
function Set-STClientCertificate {
    <#
    .SYNOPSIS
    Set what certificate is used for the Client Certificate. If a receiving server requests a Client Certificate, this is the certificate that SpamTitan will send.
    Client Certificates are only sent if a receiving server requests it. SecureMail servers will tend to request client certificates to validate the sending server.
    NOTE: Do not enable this unless required.
     
    .DESCRIPTION
    Set what certificate is used for the Client Certificate. If a receiving server requests a Client Certificate, this is the certificate that SpamTitan will send.
    Client Certificates are only sent if a receiving server requests it. SecureMail servers will tend to request client certificates to validate the sending server.
    NOTE: Do not enable this unless required.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER ClientCertificate
    The client certificate for the system
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STClientCertificate -Url $url -Token $token -ClientCertificate "example.com (self-signed)"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$ClientCertificate
    )
    Begin {
        $endpoint = "/restapi/outbound/tls/client-cert"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set Client Certificate")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                ccert= $($ClientCertificate)
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STClientCertificate.ps1' 67
#Region '.\Public\Set-STConfigurationValue.ps1' 0
function Set-STConfigurationValue {
    <#
    .SYNOPSIS
    Edits a config entry and sets it to a value
     
    .DESCRIPTION
    Edits a config entry and sets it to a value
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Configuration
    Hashtable of the configurations. See all keys by running 'Get-STConfiguration'
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>$config = @{
        domain_verify_method = "mx"
        report_name = "Avatara Spam Filter"
        report_from = "spamtitan@avataracloud.com"
        report_subject = "Spam Filter Report"
    }
    PS>Set-STConfigurationValue -Url $url -Token $token -Configuration $config
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [hashtable]$Configuration
    )
    Begin {
        $endpoint = "/restapi/config"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set Configuration")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Form $($Configuration|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STConfigurationValue.ps1' 67
#Region '.\Public\Set-STDkimAdspStatus.ps1' 0
function Set-STDkimAdspStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of ADSP Checking
     
    .DESCRIPTION
    Sets the enabled status of ADSP Checking
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDkimAdspStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/adsp"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of ADSP Checking")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDkimAdspStatus.ps1' 54
#Region '.\Public\Set-STDkimStatus.ps1' 0
function Set-STDkimStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of DKIM Checking
     
    .DESCRIPTION
    Sets the enabled status of DKIM Checking
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Enabled
    Set the enabled status. If not provided, the setting will toggle.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDkimStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim"
        [array]$Result = @()
        [hahstable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of DKIM Checking")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("Enabled"))
            {
                $body["enabled"] = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDkimStatus.ps1' 64
#Region '.\Public\Set-STDmarcArcHeaderTrust.ps1' 0
function Set-STDmarcArcHeaderTrust {
    <#
    .SYNOPSIS
    Sets whether or not DMARC will implicitly trust all ARC headers.
     
    .DESCRIPTION
    Sets whether or not DMARC will implicitly trust all ARC headers.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Enabled
    Set the enabled status. If not provided, the setting will toggle.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDmarcArcHeaderTrust -Url $url -Token $token -Enabled
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/trustarc"
        [array]$Result = @()
        [hahstable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets whether or not DMARC will implicitly trust all ARC headers.")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("Enabled"))
            {
                $body["enabled"] = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDmarcArcHeaderTrust.ps1' 64
#Region '.\Public\Set-STDmarcMailingWhitelist.ps1' 0
function Set-STDmarcMailingWhitelist {
    <#
    .SYNOPSIS
    Sets whether mailing lists are whitelisted from DMARC
     
    .DESCRIPTION
    Sets whether mailing lists are whitelisted from DMARC
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Enabled
    Set the enabled status. If not provided, the setting will toggle.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDmarcMailingWhitelist -Url $url -Token $token -Enabled
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/mailinglists"
        [array]$Result = @()
        [hahstable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets whether mailing lists are whitelisted from DMARC")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("Enabled"))
            {
                $body["enabled"] = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDmarcMailingWhitelist.ps1' 64
#Region '.\Public\Set-STDmarcPolicyAction.ps1' 0
function Set-STDmarcPolicyAction {
    <#
    .SYNOPSIS
    Sets the enabled PolicyAction of Dmarc Checking
     
    .DESCRIPTION
    Sets the enabled PolicyAction of Dmarc Checking
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Policy
    The action to be setting the action for.
 
    Allowed values: reject, quarantine
 
    .PARAMETER Action
    The action to be performed when DMARC reject policy is triggered.
 
    reject: Reject the mail with a 500 response.
    quarantine: Send the mail to quarantine for checking.
    none: Do nothing, and let the mail pass on to spam testing.
 
    Allowed values: reject, quarantine, none
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDmarcPolicyAction -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("reject","quarantine")]
        [string]$Policy,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("reject","quarantine","none")]
        [string]$Action

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/actions"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled PolicyAction of Dmarc Checking")
        {
            $api = "$($Url)$($endpoint)/$($Policy)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                action = $Action
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDmarcPolicyAction.ps1' 78
#Region '.\Public\Set-STDmarcReportingSetting.ps1' 0
function Set-STDmarcReportingSetting {
    <#
    .SYNOPSIS
    Set the DMARC reporting settings
     
    .DESCRIPTION
    Set the DMARC reporting settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER EmailAddress
    The email that DMARC reports will be sent from
 
    .PARAMETER OrganizationName
    The oganization's name that is sending the DMARC report.
 
    .PARAMETER ExtraContactInfo
    The additional contact info to provide in the DMARC report. This can be a website or an additional address
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDmarcReportingSetting -Url $url -Token $token -EmailAddress "dmarc@example.com" -OrganizationName "My Org" -ExtraContactInfo "https://example.com/en"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$EmailAddress,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$OrganizationName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$ExtraContactInfo
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/reporting"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set the DMARC reporting settings")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                email = $EmailAddress
                org_name = $OrganizationName
                extra_contact_info = $ExtraContactInfo
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDmarcReportingSetting.ps1' 74
#Region '.\Public\Set-STDmarcStatus.ps1' 0
function Set-STDmarcStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of Dmarc Checking
     
    .DESCRIPTION
    Sets the enabled status of Dmarc Checking
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Enabled
    Set the enabled status. If not provided, the setting will toggle.
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STDmarcStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled
    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc"
        [array]$Result = @()
        [hahstable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of Dmarc Checking")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("Enabled"))
            {
                $body["enabled"] = $true
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STDmarcStatus.ps1' 64
#Region '.\Public\Set-STGeoblockingStatus.ps1' 0
function Set-STGeoblockingStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of Geoblocking for the system.
    Note: This only enables/disables geoblocking for the entire system.
    If you want to enable/disable it for domain groups, domains or users, then go the respective endpoint for updating their policy.
     
    .DESCRIPTION
    Sets the enabled status of Geoblocking for the system.
    Note: This only enables/disables geoblocking for the entire system.
    If you want to enable/disable it for domain groups, domains or users, then go the respective endpoint for updating their policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STGeoblockingStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled

    )
    Begin {
        $endpoint = "/restapi/geoblocking"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of Geoblocking for the system")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header  -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STGeoblockingStatus.ps1' 61
#Region '.\Public\Set-STLicense.ps1' 0
function Set-STLicense {
    <#
    .SYNOPSIS
    Set the DMARC reporting settings
     
    .DESCRIPTION
    Set the DMARC reporting settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER LicencePath
    Path to new License
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STLicence -Url $url -Token $token -LicencePath '@/home/user/STP-2-0500-123456.key'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$LicencePath
    )
    Begin {
        $endpoint = "/restapi/license"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set ARC Key to use for ARC signing")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                license = $LicencePath
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Form $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STLicense.ps1' 63
#Region '.\Public\Set-STSandboxStatus.ps1' 0
function Set-STSandboxStatus {
    <#
    .SYNOPSIS
    Toggles Sandboxing
     
    .DESCRIPTION
    Toggles Sandboxing
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSandboxStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled

    )
    Begin {
        $endpoint = "/restapi/atp/sandboxing"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Toggles Sandboxing")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body =@{
                enabled = $Enabled
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body | ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSandboxStatus.ps1' 60
#Region '.\Public\Set-STSaslSetting.ps1' 0
function Set-STSaslSetting {
    <#
    .SYNOPSIS
    Set the SASL settings
     
    .DESCRIPTION
    Set the SASL settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSaslSetting -Url $url -Token $token -SaslSettingPath '@/home/user/STP-2-0500-123456.key'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("imap","ldap","ldaps","disabled")]
        [string]$Method,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$RequiresTls,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '(^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9]+\.)*([a-z]+|xn\-\-[a-z0-9]+)\.?$|^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$)'))
            {
                throw "Invalid IP or FQDN"
            }
            return $true
        })]
        [string]$Server,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Port = $(if($Method -imatch 'ldap|ldaps'){throw "When 'Method' set to LDAP(s), the Port is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$AnonymousSearch,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [pscredential]$Credential = $(if($Method -imatch 'ldap|ldaps'){throw "When 'Method' set to LDAP(s), the user credential is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$LdapFilter = $(if($Method -imatch 'ldap|ldaps'){throw "When 'Method' set to LDAP(s), the Filter is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$LdapSearchBase = $(if($Method -imatch 'ldap|ldaps'){throw "When 'Method' set to LDAP(s), the SearchBase is mandatory"})
    )
    Begin {
        $endpoint = "/restapi/outbound/sasl"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set the SASL settings")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                method = $Method
                server = $Server
                anonymous_search = $AnonymousSearch
                rquire_tls = $RequiresTls
            }
            if($PSBoundParameters.ContainsKey("Port"))
            {
                $body["port"] = $Port
            }
            if($PSBoundParameters.ContainsKey("Credential"))
            {
                $body["search_user"] = $Credential.UserName
                $body["search_password"] = $Credential.GetNetworkCredential().Password
            }
            if($PSBoundParameters.ContainsKey("LdapFilter"))
            {
                $body["filter"] = $LdapFilter
            }
            if($PSBoundParameters.ContainsKey("LdapSearchBase"))
            {
                $body["search_base"] = $LdapSearchBase
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Form $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSaslSetting.ps1' 103
#Region '.\Public\Set-STServerWideSmarthost.ps1' 0
function Set-STServerWideSmarthost {
    <#
    .SYNOPSIS
    Set the server-wide smarthost settings
     
    .DESCRIPTION
    Set the server-wide smarthost settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Sender
    The sender to match on. It can either be a domain (preceded by an @ symbol), or an email address.
     
    .PARAMETER Smarthost
    Address to send mail to. Has to be either an FQDN or IP (IPv4 or IPv6).
 
    .PARAMETER Port
    The port to deliver mail to at the smarthost address.
 
    Default value: 25
 
    .PARAMETER NeedAuth
    If authentication is required for the smarthost address.
 
    Default value: false
 
    .PARAMETER Credential
    [PSCredential] The Credentials to authenticate against the smarthost. Required if needauth is true.
     
    .PARAMETER Comment
    Comment
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STServerWideSmarthost -Url $url -Token $token -Smarthost "1.1.1.1"
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '(^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9]+\.)*([a-z]+|xn\-\-[a-z0-9]+)\.?$|^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$)'))
            {
                throw "Invalid IP or FQDN"
            }
            return $true
        })]
        [string]$Smarthost,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Port = 25,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$UseTls,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$NeedAuth,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [pscredential]$Credential = $(if($NeedAuth){throw "when 'NeedAuth' is used, the parameter 'Credential' is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,255)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Add Sender-based Smarthost")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                use_tls = $UseTls
                smarthost = $Smarthost
                port=$Port
            }
            if($PSBoundParameters.ContainsKey("NeedAuth"))
            {
                $body['needauth'] = $NeedAuth
            }
            if($PSBoundParameters.ContainsKey("Credential"))
            {
                $body['auth_user'] = $Credential.UserName
                $body['auth_password'] = $Credential.GetNetworkCredential().Password
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body['comment'] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STServerWideSmarthost.ps1' 114
#Region '.\Public\Set-STSpfCheckingStatus.ps1' 0
function Set-STSpfCheckingStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of SPF Checking
     
    .DESCRIPTION
    Sets the enabled status of SPF Checking
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSpfRejectionStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of SPF Checking")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSpfCheckingStatus.ps1' 54
#Region '.\Public\Set-STSpfRejectionForNonePolicy.ps1' 0
function Set-STSpfRejectionForNonePolicy {
    <#
    .SYNOPSIS
    Sets the enabled status of SPF rejection for none DMARC policies
     
    .DESCRIPTION
    Sets the enabled status of SPF rejection for none DMARC policies
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSpfRejectionForNonePolicy -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/reject/dmarc-none"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of SPF for none DMARC policies")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSpfRejectionForNonePolicy.ps1' 54
#Region '.\Public\Set-STSpfRejectionStatus.ps1' 0
function Set-STSpfRejectionStatus {
    <#
    .SYNOPSIS
    Sets the enabled status of SPF rejection
     
    .DESCRIPTION
    Sets the enabled status of SPF rejection
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSpfRejectionStatus -Url $url -Token $token
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token
    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/reject"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Sets the enabled status of SPF rejection")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSpfRejectionStatus.ps1' 54
#Region '.\Public\Set-STSystemTlsPolicy.ps1' 0
function Set-STSystemTlsPolicy {
    <#
    .SYNOPSIS
    Set what certificate is used for the Client Certificate. If a receiving server requests a Client Certificate, this is the certificate that SpamTitan will send.
    Client Certificates are only sent if a receiving server requests it. SecureMail servers will tend to request client certificates to validate the sending server.
    NOTE: Do not enable this unless required.
     
    .DESCRIPTION
    Set what certificate is used for the Client Certificate. If a receiving server requests a Client Certificate, this is the certificate that SpamTitan will send.
    Client Certificates are only sent if a receiving server requests it. SecureMail servers will tend to request client certificates to validate the sending server.
    NOTE: Do not enable this unless required.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER SystemTlsPolicy
    The client certificate for the system
 
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Set-STSystemTlsPolicy -Url $url -Token $token -SystemTlsPolicy "opportunistic"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("disabled", "opportunistic", "specified-domains", "opportunistic:specified-domains")]
        [string]$SystemTlsPolicy
    )
    Begin {
        $endpoint = "/restapi/outbound/tls/policy"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Set System TLS Policy")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                policy= $($SystemTlsPolicy)
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Set-STSystemTlsPolicy.ps1' 68
#Region '.\Public\Show-STSpfStatus.ps1' 0
function Show-STSpfStatus {
    <#
    .SYNOPSIS
    Shows whether SPF checking is enabled on the system or not.
     
    .DESCRIPTION
    Shows whether SPF checking is enabled on the system or not.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Show-STSpfStatus -Url $url -Token $token
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            return $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Show-STSpfStatus.ps1' 52
#Region '.\Public\Suspend-STDomainGroup.ps1' 0
function Suspend-STDomainGroup {
    <#
    .SYNOPSIS
    Suspends a domain group, shutting off spam, virus, and banned filtering for all domains in the domain group.
     
    .DESCRIPTION
    Suspends a domain group, shutting off spam, virus, and banned filtering for all domains in the domain group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    Target Group Id
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Suspend-STDomainGroup -Url $url -Token $token -GroupId 6
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url,"Suspends a domain group"))
        {
            
            $api = "$($Url)$($endpoint)/$($GroupId)/suspend"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try {    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Suspend-STDomainGroup.ps1' 60
#Region '.\Public\Test-STArcKey.ps1' 0
function Test-STArcKey {
    <#
    .SYNOPSIS
    Verify whether an ARC key is valid for use or not
     
    .DESCRIPTION
    Verify whether an ARC key is valid for use or not
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER ArcKey
    Target Key ID
     
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Test-STArcKey -Url $url -Token $token -ArcKeyId 45
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$ArcKeyId


    )
    Begin {
        $endpoint = "/restapi/mail-auth/arc/keys"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($ArcKeyId)/verify"
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
            $Result += $temp
        }
        catch{
            throw $_.Exception.Message
            return $temp
        }
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Test-STArcKey.ps1' 60
#Region '.\Public\Test-STDkim.ps1' 0
function Test-STDkim {
    <#
    .SYNOPSIS
    Verify a DKIM.
     
    .DESCRIPTION
    Verify a DKIM.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER DkimId
    Target DKIM Id.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Test-STDkim -Url $url -Token $token -Domain 'example.com' -DkimId 1
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Test-STDkim -Url $url -Token $token -Domain 5 -DkimId 1
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DkimId
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($Domain)/dkim/$($DkimId)/verify"
        
        $Header  = @{
    
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }
        try {
            $Result = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
        }
        catch{
            throw $_.Exception.Message
            return $Result
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Test-STDkim.ps1' 67
#Region '.\Public\Test-STIpAgainstRbl.ps1' 0
function Test-STIpAgainstRbl {
    <#
    .SYNOPSIS
    List all allowed IPs
     
    .DESCRIPTION
    List all allowed IPs
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER IpAddress
    The IP that is to be checked against the RBL list.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Test-STIpAgainstRbl-Url $url -Token $token -IpAddress "1.2.3.4"
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress
    )
    Begin {
        $endpoint = "/restapi/rbl"
        $page = 1
        [array]$Result = @()
    }
    Process {
        $api = "$($Url)$($endpoint)/$($IpAddress)/test"
        
        $Header  = @{
            "Accept" = "application/json"
            "Content-Type" = "application/json"
            "Authorization" = "Bearer $($Token)"
        }

        do{
            try {
                $temp = Invoke-RestMethod -Method Get -Uri $api -Headers $Header -ErrorAction Stop
                $Result += $temp.data
                $page ++
                $api = "$($api.split('page=')[0])page=" + "$($page)"
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
        while($temp.count -eq 500)
        
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Test-STIpAgainstRbl.ps1' 72
#Region '.\Public\Update-STAllowedIp.ps1' 0
function Update-STAllowedIp {
    <#
    .SYNOPSIS
    Updates an allowed IP
     
    .DESCRIPTION
    Updates an allowed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER AllowedIpId
    Target Allowed IP
 
    .PARAMETER IpAddress
    Sets the IP to be allowed. This can be either an IPv4 or IPv6 address
 
    .PARAMETER Mask
    Sets the subnet mask (or prefix length) to allow. This is in CIDR notation.
    The mask will only be used if a new IP is set.
 
    Default value: 32
 
    Size range: 8..128
     
    .PARAMETER Comment
    Sets the comment.
 
    Size range: ..250
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STAllowedIp -Url $url -Token $token -AllowedIpId 4 -Mask 24
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$AllowedIpId,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/ip/allow"
        [array]$Result = @()
        $body = @{
            comment = "$Comment"
        }
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update allowed IP")
        {
            $api = "$($Url)$($endpoint)/$($AllowedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body['ip'] = $IpAddress
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body['mask'] = $Mask
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STAllowedIp.ps1' 102
#Region '.\Public\Update-STAllowList.ps1' 0
function Update-STAllowList {
    <#
    .SYNOPSIS
    Update an allow-list entry
     
    .DESCRIPTION
    Update an allow-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER Sender
    Sets the sender address for the specified allow-list. Required if domain isn't provided.
     
    .PARAMETER AllowedDomain
    Sets the domain for the specified allow-list. Required if sender isn't provided.
     
    .PARAMETER IncludeSubdomains
    Sets whether to include the subdomains of a domain.
     
    .PARAMETER Comment
    Sets the comment.
 
    .PARAMETER AllowListId
    Target Allow List ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STAllowList -Url $url -Token $token -Domain "example.com" -Sender "sender@example.com" -Comment "Added via Powershell" -IncludeSubdmains
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$AllowListId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubdomains,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/allow-list"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Allow List")
        {
            $api = "$($Url)$($endpoint)/$($AllowListId)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/allow-list/$($AllowListId)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/allow-list/$($AllowListId)"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/allow-list/$($AllowListId)"
            }
            if($PSBoundParameters.ContainsKey("Sender"))
            {
                $body["sender"] = "$($Sender)"
            }
            if($PSBoundParameters.ContainsKey("IncludeSubdomains"))
            {
                $body["include_subdomains"] = $($IncludeSubdomains)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STAllowList.ps1' 119
#Region '.\Public\Update-STArcKeyComment.ps1' 0
function Update-STArcKeyComment {
    <#
    .SYNOPSIS
    Set the DMARC reporting settings
     
    .DESCRIPTION
    Set the DMARC reporting settings
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER ArcKeyId
    Target ARC key id
 
    .PARAMETER Comment
    Sets the comment.
 
    Default value: Added by API
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STArcKeyComment -Url $url -Token $token -ArcKeyId 234 -Comment "New Key"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$ArcKeyId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment = "Added by API"
    )
    Begin {
        $endpoint = "/restapi/mail-auth/mail-auth/arc"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($ArcKeyId),"Update comment")
        {
            $api = "$($Url)$($endpoint)/keys/$($ArcKeyId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                comment = $($Comment)
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertFrom-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STArcKeyComment.ps1' 69
#Region '.\Public\Update-STBlockedIp.ps1' 0
function Update-STBlockedIp {
    <#
    .SYNOPSIS
    Updates an Blocked IP
     
    .DESCRIPTION
    Updates an Blocked IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER BlockedIpId
    Target Blocked IP
 
    .PARAMETER IpAddress
    Sets the IP to be Blocked. This can be either an IPv4 or IPv6 address
 
    .PARAMETER Mask
    Sets the subnet mask (or prefix length) to allow. This is in CIDR notation.
    The mask will only be used if a new IP is set.
 
    Default value: 32
 
    Size range: 8..128
     
    .PARAMETER Comment
    Sets the comment.
 
    Size range: ..250
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STBlockedIp -Url $url -Token $token -BlockedIpId 4 -Mask 24
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$BlockedIpId,

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/ip/block"
        [array]$Result = @()
        $body = @{
            comment = "$Comment"
        }
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Blocked IP")
        {
            $api = "$($Url)$($endpoint)/$($BlockedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body['ip'] = $IpAddress
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body['mask'] = $Mask
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STBlockedIp.ps1' 102
#Region '.\Public\Update-STBlockList.ps1' 0
function Update-STBlockList {
    <#
    .SYNOPSIS
    Update an block-list entry
     
    .DESCRIPTION
    Update an block-list entry
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user or the user's email address.
     
    .PARAMETER Sender
    Sets the sender address for the specified block-list. Required if domain isn't provided.
     
    .PARAMETER blockedDomain
    Sets the domain for the specified block-list. Required if sender isn't provided.
     
    .PARAMETER IncludeSubdomains
    Sets whether to include the subdomains of a domain.
     
    .PARAMETER Comment
    Sets the comment.
 
    .PARAMETER blockListId
    Target block List ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STBlockList -Url $url -Token $token -Domain "example.com" -Sender "sender@example.com" -Comment "Added via Powershell" -IncludeSubdmains
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$blockListId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubdomains,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/block-list"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update block List")
        {
            $api = "$($Url)$($endpoint)/$($blockListId)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/block-list/$($blockListId)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/block-list/$($blockListId)"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/block-list/$($blockListId)"
            }
            if($PSBoundParameters.ContainsKey("Sender"))
            {
                $body["sender"] = "$($Sender)"
            }
            if($PSBoundParameters.ContainsKey("IncludeSubdomains"))
            {
                $body["include_subdomains"] = $($IncludeSubdomains)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STBlockList.ps1' 119
#Region '.\Public\Update-STDkimBypassedIp.ps1' 0
function Update-STDkimBypassedIp {
    <#
    .SYNOPSIS
    Updates an IP for Dkim Exemption
     
    .DESCRIPTION
    Adds a new IP for Dkim Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER DkimBypassedIpId
    Target IP Id
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-DkimBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$DkimBypassedIpId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dkim/bypass"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Dkim Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($DkimBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body["ip"] = "$($IpAddress)"
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body["mask"] = $($Mask)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = "$($Comment)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDkimBypassedIp.ps1' 96
#Region '.\Public\Update-STDmarcBypassedIp.ps1' 0
function Update-STDmarcBypassedIp {
    <#
    .SYNOPSIS
    Updates an IP for Dmarc Exemption
     
    .DESCRIPTION
    Adds a new IP for Dmarc Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER DmarcBypassedIpId
    Target IP Id
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-DmarcBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$DmarcBypassedIpId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/dmarc/bypass"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Dmarc Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($DmarcBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body["ip"] = "$($IpAddress)"
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body["mask"] = $($Mask)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = "$($Comment)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDmarcBypassedIp.ps1' 96
#Region '.\Public\Update-STDomain.ps1' 0
function Update-STDomain {
    <#
    .SYNOPSIS
    Updates a domain.
     
    .DESCRIPTION
    Updates a domain.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
 
    .PARAMETER DestinationServer
    The server to look up recipient verification against.
 
    .PARAMETER Port
    The port to test against. On Exchange 2013 or newer, this will generally need to be 2525, and for every other server type will usually be the same as your SMTP port. Default 2525
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STDomain -Url $url -Token $token -Domain "example.com" -DestinationServer "ES01.domain.com" -Port 2525
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationServer,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Port = 2525

    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Domain")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/domains"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                domain = "$($Domain)"
                destination = "$($DestinationServer)"
                rv_type = "dynamic"
                "dynamic" = @{
                    dynamic_server = "$($DestinationServer)"
                    dynamic_port = "$($port)"
                }
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDomain.ps1' 87
#Region '.\Public\Update-STDomainAuthSetting.ps1' 0
function Update-STDomainAuthSetting {
    <#
    .SYNOPSIS
    Updates specified Domain Group.
     
    .DESCRIPTION
    Updates specified Domain Group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself
 
    .PARAMETER AuthType
    The type of authentication to use for the domain.
     
    internal: Use the internal mechanisms and passwords for authentication users.
    ldap: Authentication users against an LDAP server.
    sql: Use a separate SQL server to store authentication credentials of users.
    pop: Use a POP server for authentication of users.
    imap: Use an IMAP server for authentication of users.
 
    Allowed values: internal, ldap, sql, pop, imap
 
    .PARAMETER AuthTypeParams
    Hashtable according to https://api-spamtitan.titanhq.com/#api-domains-UpdateAuthSettings
 
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STDomainAuthSetting -Url $url -Token $token -Domain "example.com" -AuthType Internal
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("internal","ldap","sql","pop","imap")]
        [string]$AuthType,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [hashtable]$AuthTypeParams
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Auth Settings")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/auth"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                auth_type = $AuthType
            }
            if($PSBoundParameters.ContainsKey("AuthTypeParams"))
            {
                $body[$AuthType] = $AuthTypeParams
            }            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDomainAuthSetting.ps1' 86
#Region '.\Public\Update-STDomainGroup.ps1' 0
function Update-STDomainGroup {
    <#
    .SYNOPSIS
    Updates specified Domain Group.
     
    .DESCRIPTION
    Updates specified Domain Group.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER GroupId
    Target Group Id
 
     
    .PARAMETER Name
    The name of the domain group
 
    .PARAMETER Timezone
    The timezone of the domain group. You can find a list of names below. Utilize the TZ database name column for the timezone name to provide.
 
    .PARAMETER Description
    The description of the domain group.
 
    .PARAMETER License
    The license assigned to the domain group. Does not affect anything.
 
    .PARAMETER GeoBlocking
    Whether to enable geoblocking.
    Default value: true
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STDomainGroup -Url $url -Token $token -GroupId 5 -Name "MyGroupName"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Name,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Timezone,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Description,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$License,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [bool]$GeoBlocking
    )
    Begin {
        $endpoint = "/restapi/domain-groups"
        [array]$Result = @()
        $Exclude = @('Url','Token','GroupId')
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Domain Group")
        {
            [hashtable]$body = @{}
            $api = "$($Url)$($endpoint)/$($GroupId)"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $PSBoundParameters | ForEach-Object {
                if($_.Key -inotin $Exclude)
                {
                    $body[$_.Key.ToLower()] = $_.Value
                }
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDomainGroup.ps1' 95
#Region '.\Public\Update-STDomainPolicy.ps1' 0
function Update-STDomainPolicy {
    <#
    .SYNOPSIS
    Update a specified domain's policy
     
    .DESCRIPTION
    Update a specified domain's policy
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GeoBlocking
    Whether to enable geoblocking.
 
    Default value: true
     
    .PARAMETER ArchiveCleanMail
    Whether to store a copy of clean mail in the quarantine for a temporary archive.
 
    Default value: false
     
    .PARAMETER SpamEnabled
    Whether spam filtering is enabled.
     
    .PARAMETER SpamAction
    What to do with a mail marked as spam. Whether to tag and pass it, quarantine it, or reject the mail (delete and send an NDR).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER SpamScore
    The score to determine if a mail is spam. Score for the mail has to be greater than this value to be considered Spam.
    Default value: 5
 
    .PARAMETER SpamSendNdr
    Whether to send an NDR if a mail is quarantined. Only used if the spam_action is quarantine.
    Default value: false
     
    .PARAMETER SpamDiscardScore
    The score to discard the mail at. If the score of the mail is over the spam_discard_score, then the mail will be deleted instead of being quarantined.
    Default value: 999
     
    .PARAMETER SpamAddHeaders
    To include the X-Spam headers to non-spam mails.
    Default value: true
     
    .PARAMETER VirusEnabled
    Whether virus filtering is enabled.
     
    .PARAMETER Sandbox
    Whether or not to send viruses that need sandboxing to the sandbox
     
    .PARAMETER VirusAction
    What to do with a mail marked as a virus. Whether to tag and pass it, quarantine it, or reject the mail (delete the mail).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER AttachmentEnabled
    Whether banned attachment filtering is enabled.
     
    .PARAMETER AttachmentAction
    What to do with a mail marked as a banned attachment. Whether to tag and pass it, quarantine it, or reject the mail (delete the mail).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER QreportEnabled
    Whether the user should receive a quarantine report for quarantined items.
     
    .PARAMETER QreportLanguage
    The language for the quarantine report to be in
    Default value: en_us
 
    .PARAMETER QreportFrequency
    How often to send the mail.
    Values:
 
        D: Daily
        N: Never
        W: Weekly
        WD: Every Week Day
        M: Monthly
 
    Default value: D
 
    Allowed values: N, D, W, WD, M
     
    .PARAMETER QreportContains
    What quarantine reports contain.
    Values:
 
        A: All items in quarantine.
        N: New items since last report.
        AX: All items except Viruses in Quarantine.
        NX: New items except Viruses since last report.
 
    Default value: N
 
    Allowed values: A, N, AX, NX
     
    .PARAMETER QreportExcludeScore
    The score threshold to exclude mails scoring over it from the quarantine report.
 
    Default value: 999
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STDomainPolicy -Url $url -Token $token -Domain "example.com" -GeoBlocking
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$GeoBlocking,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ArchiveCleanMail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$SpamAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamSendNdr,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamDiscardScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamAddHeaders,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$VirusEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Sandbox,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$VirusAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$AttachmentEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$AttachmentAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$QreportEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("cs_cz","zh_cn","da_dk","nl_nl","en_us","fr_fr","de_de","he_il","it_it","ja_jp","nb_no","pl_pl","pt_br","ru_ru","es_es","sv_se","th_th","tr_tr")]
        [string]$QreportLanguage,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("D","N","W","WD","M")]
        [string]$QreportFrequency,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("A","N","AX","NX")]
        [string]$QreportContains,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$QreportExcludeScore
        
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Domain Policy")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/Policy"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("GeoBlocking"))
            {
                $body["geoblocking"] = $GeoBlocking
            }
            if($PSBoundParameters.ContainsKey("ArchiveCleanMail"))
            {
                $body["archive_clean_mail"] = $ArchiveCleanMail
            }
            if($PSBoundParameters.ContainsKey("SpamEnabled"))
            {
                $body["spam_enabled"] = $SpamEnabled
            }
            if($PSBoundParameters.ContainsKey("SpamAction"))
            {
                $body["spam_action"] = $SpamAction
            }
            if($PSBoundParameters.ContainsKey("SpamScore"))
            {
                $body["spam_score"] = $SpamScore
            }
            if($PSBoundParameters.ContainsKey("SpamSendNdr"))
            {
                $body["spam_send_ndr"] = $SpamSendNdr
            }
            if($PSBoundParameters.ContainsKey("SpamDiscardScore"))
            {
                $body["spam_discard_score"] = $SpamDiscardScore
            }
            if($PSBoundParameters.ContainsKey("SpamAddHeaders"))
            {
                $body["spam_add_headers"] = $SpamAddHeaders
            }
            if($PSBoundParameters.ContainsKey("VirusEnabled"))
            {
                $body["virus_enabled"] = $VirusEnabled
            }
            if($PSBoundParameters.ContainsKey("VirusAction"))
            {
                $body["virus_action"] = $VirusAction
            }
            if($PSBoundParameters.ContainsKey("Sandbox"))
            {
                $body["sandbox"] = $Sandbox
            }
            if($PSBoundParameters.ContainsKey("AttachmentEnabled"))
            {
                $body["attachment_enabled"] = $AttachmentEnabled
            }
            if($PSBoundParameters.ContainsKey("AttachmentAction"))
            {
                $body["attachment_action"] = $AttachmentAction
            }
                if($PSBoundParameters.ContainsKey("QreportEnabled"))
            {
                $body["qreport_enabled"] = $QreportEnabled
            }
            if($PSBoundParameters.ContainsKey("QreportLanguage"))
            {
                $body["qreport_language"] = $QreportLanguage
            }
            if($PSBoundParameters.ContainsKey("QreportFrequency"))
            {
                $body["qreport_frequency"] = $QreportFrequency
            }
            if($PSBoundParameters.ContainsKey("QreportContains"))
            {
                $body["qreport_contains"] = $QreportContains
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STDomainPolicy.ps1' 260
#Region '.\Public\Update-STGeoblockingExemption.ps1' 0
function Update-STGeoblockingExemption {
    <#
    .SYNOPSIS
    Creates a geoblocking sender exemption for global, domain group, domain or user.
     
    .DESCRIPTION
    Creates a geoblocking sender exemption for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER DomainId
    The ID of the domain.
     
    .PARAMETER UserId
    The ID of the user.
     
    .PARAMETER Comment
    Sets the comment.
 
    Size range: ..250
     
    .PARAMETER Domain
    The sender domain address to exclude from geo-blocking checks. Required if neither email nor ip is provided.
     
    .PARAMETER Email
    The sender email address to exclude from geo-blocking checks. Required if neither domain nor ip is provided.
     
    .PARAMETER IpAddress
    The sender ip address to exclude from geo-blocking checks. Required if neither domain nor email is provided.
     
    .PARAMETER IncludeSubDomain
    Sets whether to include the IncludeSubDomains of the specified domain.
 
    Default value: false
     
    .PARAMETER Mask
    The sender subnet mask to exclude from geo blocking checks. This is in CIDR notation.
    Default value: 32
    Size range: 8..32
 
    .PARAMETER ExemptionId
    Target Exemption ID
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STGeoblockingExemption -Url $url -Token $token -Domain 'example.com' -IncludeSubDomain
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$ExemptionId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$DomainId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain = $(if(-not ($Email) -and -not ($IpAddress)){throw "The parameter 'Domain' is mandatory when 'Email' or 'IpAddress' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Email = $(if(-not ($Domain) -and -not ($IpAddress)){throw "The parameter 'Email' is mandatory when 'Domain' or 'IpAddress' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$IpAddress = $(if(-not ($Domain) -and -not ($Email)){throw "The parameter 'IpAddress' is mandatory when 'Domain' or 'Email' are not provided"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$IncludeSubDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,32)]
        [string]$Mask = 32
    )
    Begin {
        $endpoint = "/restapi/geo-exemptions/$($ExemptionId)"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Geoblocking Exemption")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("GroupId"))
            {
                $api = "$($Url)/domain-groups/$($GroupId)/geo-exemptions/$($ExemptionId)"
            }
            if($PSBoundParameters.containskey("Domain"))
            {
                $api = "$($Url)/domains/$($Domain)/geo-exemptions/$($ExemptionId)"
            }
            if($PSBoundParameters.containskey("UserId"))
            {
                $api = "$($Url)/users/$($UserId)/geo-exemptions/$($ExemptionId)"
            }
            if($PSBoundParameters.containskey("Comment"))
            {
                $body["comment"] = $Comment
            }
            if($PSBoundParameters.containskey("Domain"))
            {
                $body["domain"] = $Domain
            }
            if($PSBoundParameters.containskey("Email"))
            {
                $body["email"] = $Email
            }
            if($PSBoundParameters.containskey("IpAddress"))
            {
                $body["ip"] = $($IpAddress)
            }
            if($PSBoundParameters.containskey("IncludeSubDomain"))
            {
                $body["IncludeSubDomains"] = $IncludeSubDomain
            }
            if($PSBoundParameters.containskey("Mask"))
            {
                $body["mask"] = $Mask
            }
            try {
                $temp = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body | ConvertTo-Json -Depth 99) -ErrorAction Stop
                $Result += $temp.data
            }
            catch{
                throw $_.Exception.Message
                return $temp
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STGeoblockingExemption.ps1' 149
#Region '.\Public\Update-STGeoblockingRule.ps1' 0
function Update-STGeoblockingRule {
    <#
    .SYNOPSIS
    Updates a geoblocking rule for global, domain group, domain or user.
     
    .DESCRIPTION
    Updates a geoblocking rule for global, domain group, domain or user.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER UserId
    The ID of the user
     
    .PARAMETER CountryIso
    The 2 digit ISO country code.
 
    .PARAMETER Geoblock
    Sets whether to block emails from a specified country.
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STGeoblockingRule -Url $url -Token $token -CountryIso US -Geoblock -GroupId 5
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet([CountryIsos])]
        [string]$CountryIso,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Geoblock

    )
    Begin {
        $endpoint = "/restapi/geo-rules"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($CountryIso),"Update Geoblocking Rule")
        {
            $api = "$($Url)$($endpoint)/$($CountryIso)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/geo-rules/$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/geo-rules/$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("UserId"))
            {
                $api = "$($Url)/restapi/users/$($UserId)/geo-rules/$($CountryIso)"
            }
            if($PSBoundParameters.ContainsKey("Geoblock"))
            {
                $body["geoblock"] = $($Geoblock)
            }
            else
            {
                $body["geoblock"] = $false
            }
            

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STGeoblockingRule.ps1' 104
#Region '.\Public\Update-STOutboundPolicy.ps1' 0
function Update-STOutboundPolicy {
    <#
    .SYNOPSIS
    Updates an allowed IP
     
    .DESCRIPTION
    Updates an allowed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STOutboundPolicy -Url $url -Token $token -OutboundPolicyId 4 -Mask 24
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$PolicyName,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ArchiveCleanEmail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$SpamAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamSendNdr,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamDiscardScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamAddHeaders,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$VirusEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$VirusAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Sandbox,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$AttachmentEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$AttachmentAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$QreportEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("cs_cz","zh_cn","da_dk","nl_nl","en_us","fr_fr","de_de","he_il","it_it","ja_jp","nb_no","pl_pl","pt_br","ru_ru","es_es","sv_se","th_th","tr_tr")]
        [string]$QreportLanguage,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("D","N","W","WD","M")]
        [string]$QreportFrequency,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("A", "N", "AX", "NX")]
        [string]$QreportContains,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$QreportExcludeScore
        

    )
    Begin {
        $endpoint = "/restapi/outbound/policy"
        [array]$Result = @()
        $body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update allowed IP")
        {
            $api = "$($Url)$($endpoint)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.containskey("PolicyName"))
            {
                $body['policy_name'] = $PolicyName
            }
            if($PSBoundParameters.containskey("ArchiveCleanMail"))
            {
                $body['archive_clean_mail'] = $ArchiveCleanEmail
            }
            if($PSBoundParameters.containskey("SpamEnabled"))
            {
                $body['spam_enabled'] = $SpamEnabled
            }
            if($PSBoundParameters.containskey("SpamAction"))
            {
                $body['spam_action'] = $SpamAction
            }
            if($PSBoundParameters.containskey("SpamScore"))
            {
                $body['spam_score'] = $SpamScore
            }
            if($PSBoundParameters.containskey("SpamSendNdr"))
            {
                $body['spam_send_ndr'] = $SpamSendNdr
            }
            if($PSBoundParameters.containskey("SpamDiscardScore"))
            {
                $body['spam_discard_score'] = $SpamDiscardScore
            }
            if($PSBoundParameters.containskey("SpamAddHeaders"))
            {
                $body['spam_add_headers'] = $SpamAddHeaders
            }
            if($PSBoundParameters.containskey("VirusEnabled"))
            {
                $body['virus_enabled'] = $VirusEnabled
            }
            if($PSBoundParameters.containskey("VirusAction"))
            {
                $body['virus_action'] = $VirusAction
            }
            if($PSBoundParameters.containskey("Sandbox"))
            {
                $body['sandbox'] = $Sandbox
            }
            if($PSBoundParameters.containskey("AttachmentEnabled"))
            {
                $body['attachment_enabled'] = $AttachmentEnabled
            }
            if($PSBoundParameters.containskey("AttachmentAction"))
            {
                $body['attachment_action'] = $AttachmentAction
            }
            if($PSBoundParameters.containskey("QreportEnabled"))
            {
                $body['qreport_enabled'] = $QreportEnabled
            }
            if($PSBoundParameters.containskey("QreportLanguage"))
            {
                $body['qreport_language'] = $QreportLanguage
            }
            if($PSBoundParameters.containskey("QreportFrequency"))
            {
                $body['qreport_frequency'] = $QreportFrequency
            }
            if($PSBoundParameters.containskey("QreportContains"))
            {
                $body['qreport_contains'] = $QreportContains
            }
            if($PSBoundParameters.containskey("QreportExcludeScore"))
            {
                $body['qreport_exclude_score'] = $QreportExcludeScore
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STOutboundPolicy.ps1' 171
#Region '.\Public\Update-STPattern.ps1' 0
function Update-STPattern {
    <#
    .SYNOPSIS
    Updates a pattern filter
     
    .DESCRIPTION
    Updates a pattern filter
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
     
    .PARAMETER GroupId
    The ID of the domain group.
 
    .PARAMETER PatternId
    Target pattern ID
     
    .PARAMETER Pattern
    The pattern for the pattern filter.
     
    .PARAMETER Type
    The way to utilize the pattern. Available filter types:
 
    regex: Pattern is a Regular Expression
    contains: Pattern exists somewhere in body/header.
    startswith: Body/header starts with pattern.
    endswith: Body/header ends with pattern.
    exact: Body/header exactly matches pattern.
    anyword: Pattern is a string of words separated by spaces, and any word in that list can exist in body/header.
    meta: Advanced matching for creating meta rules. RULE_<ID> is how you match against another Pattern Filter (said Pattern Filter must be in test mode), or you can specify the name of the rule you wish to match directly. Use && for AND and || for OR, you may wrap rules in parenthesis to match a grouping.
 
    Default value: regex
 
    Allowed values: regex, contains, startswith, endswith, exact, anyword, meta
     
    .PARAMETER ApplyBody
    Apply the pattern filter to the body. You must set either this or apply_headers to true, or both.
 
    Default value: false
     
    .PARAMETER RawBody
    If apply_body is true, then this makes the pattern filter trigger against the raw body of the email, allowing it to trigger on HTML tags and the like.
 
    Default value: false
     
    .PARAMETER ApplyHeaders
    Apply the pattern filter to the body. You must set either this or apply_body to true, or both.
 
    Default value: false
     
    .PARAMETER Headers
    If apply_headers is true, the this determines what headers to trigger on in the email.
 
    Default value: ALL
     
    .PARAMETER Score
    This is the score to add to an email if the pattern filter triggers. Setting this to 0 puts the pattern filter into test mode. Setting this above 0 classifies it as a blocked pattern. Setting this below 0 classifies it as an allowed pattern.
 
    Default value: 0
 
    Size range: -100 to 100
     
    .PARAMETER DisableRule
    Set the pattern filter to disabled or not.
 
    Default value: false
     
    .PARAMETER Comment
    The comment for the pattern filter.
 
    Default value: Added by API
 
    Size range: ..250
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STPattern -Url $url -Token $token -PaternId 4 -Type Regex -Pattern '[Mm]alicious\s[Aa]ctivity'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$PatternId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Pattern,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("regex","contains","startswith","endswith","exact","anyword","meta")]
        [string]$Type = "regex",
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ApplyBody,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$RawBody,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ApplyHeaders,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string[]]$Headers = "ALL",
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(-100,100)]
        [int]$Score = 0,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$DisableRule,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/patterns"
        [array]$Result = @()
        [hashtable]$body = @{
            pattern = "$($Pattern)"
            type = "$($Type)"
            headers = @($Headers)
            score = $Score
            comment = $Comment
        }
    }
    Process {
        if($PSCmdlet.ShouldProcess($PatternId),"Update pattern filter")
        {
            $api = "$($Url)$($endpoint)/$($PatternId)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/patterns/$($PatternId)"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/patterns/$($PatternId)"
            }
            if($PSBoundParameters.containskey("ApplyBody"))
            {
                $body["apply_body"] = $ApplyBody
            }
            if($PSBoundParameters.containskey("RawBody"))
            {
                $body["rawbody"] = $RawBody
            }
            if($PSBoundParameters.containskey("ApplyHeaders"))
            {
                $body["apply_headers"] = $ApplyHeaders
            }
            if($PSBoundParameters.containskey("DisableRule"))
            {
                $body["disable_rule"] = $DisableRule
            }
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STPattern.ps1' 177
#Region '.\Public\Update-STRateControlPolicy.ps1' 0
function Update-STRateControlPolicy {
    <#
    .SYNOPSIS
    Updates specified Rate Control Policy
     
    .DESCRIPTION
    Updates specified Rate Control Policy
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Name
    The name of the Rate Control Policy.
 
    Size range: ..250
     
    .PARAMETER Enabled
    Whether or not the Rate Control Policy is enabled
     
    .PARAMETER Source
    What kind of source to be looking at.
 
    any: Tracks emails from any sources.
    internal: Tracks emails from Trusted Networks.
    external: Tracks emails that aren't from Trusted Networks.
    domain: Must provide source_domain to specify what domain to track.
    email: Must provide source_email to specify what email to track.
    cidr: Must provide source_cidr to specify what CIDR to track.
 
    Allowed values: any, internal, external, domain, email, cidr
     
    .PARAMETER SourceEmail
    The email to track in the source. Required if source is set to email
     
    .PARAMETER SourceDomain
    he domain to track in the source. Required if source is set to domain
     
    .PARAMETER SourceCidr
    The CIDR to track in the source. Required if source is set to cidr.
     
    .PARAMETER Destination
    What kind of destination to follow.
 
    any: Tracks emails to any destination.
    domain: Must provide the destination_domainto specify what email to track.
    email: Must provide the destination_emailto specify what email to track.
 
    Allowed values: any, domain, email
     
    .PARAMETER DestinationEmail
    The email destination to track. Required if destination is set to email
     
    .PARAMETER DestinationDomain
    The domain destination to track. Required if destination is set to domain
     
    .PARAMETER Track
    What type of thing to count for tracking rate controls.
 
    Allowed values: ip, sender, email, sender, domain, recipient, email, recipient, domain
     
    .PARAMETER Bitmask
    The CIDR bitmask to track. Required if track is set to ip.
 
    Size range: 8..32
     
    .PARAMETER StopProcessing
    Whether to stop processing more policies after this policy has been hit
     
    .PARAMETER Priority
    The priority of the policy. Lower numbers represent higher priority. Priority 1 will be the first checked.
 
    Size range: 1..32767
     
    .PARAMETER RateLimit
    What to rate limit based off of. Either the Message Count of the Cumulative size of the messages (in kB).
 
    Allowed values: MessageCount, MessageCumulativeSize
     
    .PARAMETER LimitCount
    The number of mails to hit the limit before executing the action.
 
    Size range: 1..
     
    .PARAMETER Period
    The period of time to listen to the tracking to detect exceeded limits. This is over a rolling period of time. This is over the period of time in period_unit.
 
    Size range: 1..
     
    .PARAMETER PeriodUnit
    The unit the period should be tracked in.
 
    Allowed values: second, minute, hour
     
    .PARAMETER Action
    Whether to defer (4XX response) mails that exceed the rate limit, or reject (5XX response) them outright.
 
    Allowed values: DEFER, REJECT
     
    .PARAMETER SmtpResponse
    The text/response to go alongside the action.
 
    Size range: ..250
     
    .PARAMETER NotifyAdmin
    Whether to notify an administrator when the rate limit has been exceeded
     
    .PARAMETER NotifyAddress
    The address to send notifications to. Required if notify_admin is true
     
    .PARAMETER Comment
    A comment to associate with the policy.
 
    Default value: Added by API
 
    Size range: ..250
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS> $splat = @{
        Url = $url
        Token = $token
        Name= "Example"
        Enabled = $true
        Source= "any"
        Destination= "any"
        Track= "sender"
        StopProcessing = $true
        Priority = 3
        RateLimit = "MessageCount"
        LimitCount = 50
        Period = 30
        PeriodUnit = "minute"
        Action = "REJECT"
        SmtpResponse = "An Example policy"
        NotifyAdmin = $true
        NotifyAddress = "admin@example.com"
    }
    PS>Update-STRateControlPolicy @splat
    #>

    
    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Name,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Enabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("any", "internal", "external", "domain", "email", "cidr")]
        [string]$Source,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceEmail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$SourceCidr,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("any", "domain", "email")]
        [string]$Destination,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationEmail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$DestinationDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("ip", "sender", "email", "sender", "domain", "recipient", "email", "recipient", "domain")]
        [string]$Track,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,32)]
        [string]$Bitmask,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$StopProcessing,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(1,32767)]
        [int]$Priority,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("MessageCount", "MessageCumulativeSize")]
        [string]$RateLimit,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({if(-not ($_ -gt 0)){throw "Limit must be > 0"}return $true})]
        [int]$LimitCount,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({if(-not ($_ -gt 0)){throw "Period must be > 0"}return $true})]
        [int]$Period,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("second", "minute", "hour")]
        [string]$PeriodUnit,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("DEFER", "REJECT")]
        [string]$Action,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$SmtpResponse,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$NotifyAdmin,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$NotifyAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/rate-controls/policies"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Rate Control Policy")
        {
            $api = "$($Url)$($endpoint)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("Name"))
            {
                $body["name"] = $Name
            }
            if($PSBoundParameters.ContainsKey("Enabled"))
            {
                $body["enabled"] = $Enabled
            }
            if($PSBoundParameters.ContainsKey("Source"))
            {
                $body["source"] = $Source
            }
            if($PSBoundParameters.ContainsKey("SourceEmail"))
            {
                $body["source_email"] = $SourceEmail
            }
            if($PSBoundParameters.ContainsKey("SourceDomain"))
            {
                $body["source_domain"] = $SourceDomain
            }
            if($PSBoundParameters.ContainsKey("SourceCidr"))
            {
                $body["source_cidr"] = $SourceCidr
            }
            if($PSBoundParameters.ContainsKey("Destination"))
            {
                $body["destination"] = $Destination
            }
            if($PSBoundParameters.ContainsKey("DestinationEmail"))
            {
                $body["destination_email"] = $DestinationEmail
            }
            if($PSBoundParameters.ContainsKey("DestinationDomain"))
            {
                $body["destination_domain"] = $DestinationDomain
            }
            if($PSBoundParameters.ContainsKey("Track"))
            {
                $body["track"] = $Track
            }

            if($PSBoundParameters.ContainsKey("Bitmask"))
            {
                $body["bitmask"] = $Bitmask
            }
            if($PSBoundParameters.ContainsKey("StopPorcessing"))
            {
                $body["stop_processing"] = $StopProcessing
            }
            if($PSBoundParameters.ContainsKey("Priority"))
            {
                $body["priority"] = $Priority
            }
            if($PSBoundParameters.ContainsKey("RateLimit"))
            {
                $body["rate_limit"] = $RateLimit
            }
            if($PSBoundParameters.ContainsKey("LimitCount"))
            {
                $body["limit_count"] = $LimitCount
            }
            if($PSBoundParameters.ContainsKey("Period"))
            {
                $body["period"] = $Period
            }
            if($PSBoundParameters.ContainsKey("PeriodUnit"))
            {
                $body["period_unit"] = $PeriodUnit
            }
            if($PSBoundParameters.ContainsKey("Action"))
            {
                $body["action"] = $Action
            }
            if($PSBoundParameters.ContainsKey("SmtpResponse"))
            {
                $body["smtp_response"] = $SmtpResponse
            }
            if($PSBoundParameters.ContainsKey("NotifyAdmin"))
            {
                $body["notify_admin"] = $NotifyAdmin
            }
            if($PSBoundParameters.ContainsKey("NotifyAddress"))
            {
                $body["notify_address"] = $NotifyAddress
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Post -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STRateControlPolicy.ps1' 325
#Region '.\Public\Update-STRbl.ps1' 0
function Update-STRbl {
    <#
    .SYNOPSIS
    Updates a RBL
     
    .DESCRIPTION
    Updates a RBL
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Rbl
    Current RBL
 
    .PARAMETER NewRbl
    New RBL
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STRbl -Url $url -Token $token -Rbl 'kitten.gbudb.net' -NewRbl 'truncate.gbudb.net'
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Rbl,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$NewRbl

    )
    Begin {
        $endpoint = "/restapi/rbl"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update Rbl")
        {
            $api = "$($Url)$($endpoint)/$($Rbl)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                new_rbl = $*($NewRbl)
                }
            
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STRbl.ps1' 68
#Region '.\Public\Update-STRblBypassedIp.ps1' 0
function Update-STRblBypassedIp {
    <#
    .SYNOPSIS
    Update RBL Bypassed IP
     
    .DESCRIPTION
    Update RBL Bypassed IP
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER RblBypassedIpId
    Target Bypassed IP Id.
     
    .PARAMETER IpAddress
    Ip address to be Updated
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STRblBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns" -RblBypassedIpId 3
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$RblBypassedIpId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/rbl/bypass"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update RBL Bypassed IP")
        {
            $api = "$($Url)$($endpoint)/$($RblBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body["ip"] = "$($IpAddress)"
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body["mask"] = $($Mask)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = "$($Comment)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STRblBypassedIp.ps1' 96
#Region '.\Public\Update-STSenderBasedSmarthost.ps1' 0
function Update-STSenderBasedSmarthost {
    <#
    .SYNOPSIS
    Update sender-based Smarthost.
     
    .DESCRIPTION
    Update sender-based Smarthost.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER Sender
    The sender to match on. It can either be a domain (preceded by an @ symbol), or an email address.
     
    .PARAMETER Smarthost
    Address to send mail to. Has to be either an FQDN or IP (IPv4 or IPv6).
    .PARAMETER Port
    The port to deliver mail to at the smarthost address.
 
    Default value: 25
    .PARAMETER NeedAuth
    If authentication is required for the smarthost address.
 
    Default value: false
    .PARAMETER Credential
    [PSCredential] The Credentials to authenticate against the smarthost. Required if needauth is true.
    .PARAMETER Comment
    Comment
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Add-STSenderBasedSmarthost -Url $url -Token $token -Sender "user@example.com" -Smarthost "1.1.1.1" -Port 25
     
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Sender,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$SmarthostId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '(^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9]+\.)*([a-z]+|xn\-\-[a-z0-9]+)\.?$|^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$)'))
            {
                throw "Invalid IP or FQDN"
            }
            return $true
        })]
        [string]$Smarthost,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$Port = 25,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$NeedAuth,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [pscredential]$Credential = $(if($NeedAuth){throw "when 'NeedAuth' is used, the parameter 'Credential' is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,255)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/outbound/smarthost/sender"
        [array]$Result = @()
    }
    Process {
        if($PSCmdlet.ShouldProcess($UserId),"Update Sender-based Smarthost")
        {
            $api = "$($Url)$($endpoint)/$($SmarthostId)"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            $body = @{
                port=$Port
            }
            if($PSBoundParameters.ContainsKey("Sender"))
            {
                $body['sender'] = $Sender
            }
            if($PSBoundParameters.ContainsKey("Smarthost"))
            {
                $body['smarthost'] = $Smarthost
            }
            if($PSBoundParameters.ContainsKey("NeedAuth"))
            {
                $body['needauth'] = $NeedAuth
            }
            if($PSBoundParameters.ContainsKey("Credential"))
            {
                $body['auth_user'] = $Credential.UserName
                $body['auth_password'] = $Credential.GetNetworkCredential().Password
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body['comment'] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STSenderBasedSmarthost.ps1' 118
#Region '.\Public\Update-STSpfBypassedIp.ps1' 0
function Update-STSpfBypassedIp {
    <#
    .SYNOPSIS
    Updates an IP for SPF Exemption
     
    .DESCRIPTION
    Updates an IP for SPF Exemption
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER SpfBypassedIpId
    Target IP Id
     
    .PARAMETER IpAddress
    Ip address to be blocked
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-SpfBypassedIp -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$SpfBypassedIpId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/mail-auth/spf/bypass"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update SPF Bypass IP")
        {
            $api = "$($Url)$($endpoint)/$($SpfBypassedIpId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body["ip"] = "$($IpAddress)"
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body["mask"] = $($Mask)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = "$($Comment)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STSpfBypassedIp.ps1' 96
#Region '.\Public\Update-STTlsPolicy.ps1' 0
function Update-STTlsPolicy {
    <#
    .SYNOPSIS
    Update a specific TLS Exception Policies. This is a per-recipient TLS Policy.
     
    .DESCRIPTION
    Update a specific TLS Exception Policies. This is a per-recipient TLS Policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The ID of the domain or the domain itself.
 
    .PARAMETER SubDomain
    Whether to include subdomains as well.
 
    Default value: false
 
    .PARAMETER Policy
    What TLS policy to set.
 
    Allowed values: none, may, encrypt, verify
 
    .PARAMETER Protocols
    The protocols to use if the policy is set to encrypt or verify.
 
    Allowed values: SSLv2, SSLv3, !SSLv2:!SSLv3, SSLv2:SSLv3, SSLv3:TLSv1, SSLv2:SSLv3:TLSv1
 
    .PARAMETER Comment
    The comment for the policy.
 
    Default value: Added by API
 
    Size range: ..250
 
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STTlsPolicy -Url $url -Token $token -Domain "example.com" -Policy "encrypt" -Protocols "SSLv3:TLSv1" -Comment "Added by API"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SubDomain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("none","may","encrypt","verify")]
        [string]$Policy,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("SSLv2", "SSLv3", "!SSLv2:!SSLv3", "SSLv2:SSLv3", "SSLv3:TLSv1", "SSLv2:SSLv3:TLSv1")]
        [string]$Protocols = $(if($Policy -imatch 'encrypt|verify'){throw "when 'Policy' is set to 'encrypt' or 'verify', the Protocols parameter is mandatory"}),
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateLength(0,250)]
        [string]$Comment
    )
    Begin {
        $endpoint = "/restapi/domains"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Add TLS Policy")
        {
            $api = "$($Url)$($endpoint)/$($Domain)/dkim"
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $body["domain"] = $Domain
            }
            if($PSBoundParameters.ContainsKey("Policy"))
            {
                $body["policy"] = $Policy
            }
            if($PSBoundParameters.ContainsKey("SubDomain"))
            {
                $body["subdomain"] = $SubDomain
            }
            if($PSBoundParameters.ContainsKey("Protocols"))
            {
                $body["protocols"] = $Protocols
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = $Comment
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STTlsPolicy.ps1' 113
#Region '.\Public\Update-STTrustedNetwork.ps1' 0
function Update-STTrustedNetwork {
    <#
    .SYNOPSIS
    Update a Trusted Network
     
    .DESCRIPTION
    Update a Trusted Network
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
 
    .PARAMETER TrustedNetworkId
    Target Trusted Network Id.
     
    .PARAMETER IpAddress
    Ip address to be Updated
 
    .PARAMETER Mask
    Subnet mask. Blocked values 8..128
 
    .PARAMETER Comment
    Comment
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STTrustedNetwork -Url $url -Token $token -IpAddress 8.8.8.8 -Mask 32 -Comment "Allow google dns" -TrustedNetworkId 3
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if($_ -inotmatch '^(((1?[1-9]?|10|2[0-4])\d|25[0-5])($|\.(?!$))){4}$')
            {
                throw "Invalid IP address"
            }
            return $true
        })]
        [string]$IpAddress,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [int]$TrustedNetworkId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateRange(8,128)]
        [int]$Mask = 32,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Comment

    )
    Begin {
        $endpoint = "/restapi/outbound/trusted"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update a Trusted Network")
        {
            $api = "$($Url)$($endpoint)/$($TrustedNetworkId)"
            
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("IpAddress"))
            {
                $body["ip"] = "$($IpAddress)"
            }
            if($PSBoundParameters.ContainsKey("Mask"))
            {
                $body["mask"] = $($Mask)
            }
            if($PSBoundParameters.ContainsKey("Comment"))
            {
                $body["comment"] = "$($Comment)"
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STTrustedNetwork.ps1' 96
#Region '.\Public\Update-STUser.ps1' 0
function Update-STUser {
    <#
    .SYNOPSIS
    Creates a new user
     
    .DESCRIPTION
    Creates a new user
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER Domain
    The domain to be created.
 
    .PARAMETER GroupId
    The ID of the domain group
     
    .PARAMETER EmailAddress
    New user email address
     
    .PARAMETER RoleId
    Role id the new user will receive
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>New-STUser -Url $url -Token $token -Domain "example.com" -EmailAddress "user@example.com"
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Domain,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$GroupId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateScript({
            if(-not ($_ -imatch '^(?:(?!.*?[.]{2})[a-zA-Z0-9](?:[a-zA-Z0-9.+!%-]{1,64}|)|\"[a-zA-Z0-9.+!% -]{1,64}\")@[a-zA-Z0-9][a-zA-Z0-9.-]+(.[a-z]{2,}|.[0-9]{1,})$'))
            {
                throw "Invalid Email address"
            }
            return $true
        })]
        [string]$EmailAddress,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$RoleId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [securestring]$Password
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Create new User")
        {
            $api = "$($Url)$($endpoint)"
            if($PSBoundParameters.ContainsKey("GroupId"))
            {
                $api = "$($Url)/restapi/domain-groups/$($GroupId)/users"
            }
            if($PSBoundParameters.ContainsKey("Domain"))
            {
                $api = "$($Url)/restapi/domains/$($Domain)/users"
            }
            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("EmailAddress"))
            {
                $body["email"] = $EmailAddress
            }
            if($PSBoundParameters.ContainsKey("RoleId"))
            {
                $body["id"] = $RoleId
            }
            if($PSBoundParameters.ContainsKey("Password"))
            {
                $body["password"] = $($Password | ConvertFrom-SecureString -AsPlainText)
                $body["confim_password"] = $($Password | ConvertFrom-SecureString -AsPlainText)
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STUser.ps1' 104
#Region '.\Public\Update-STUserPolicy.ps1' 0
function Update-STUserPolicy {
    <#
    .SYNOPSIS
    Update a specified User's policy.
     
    .DESCRIPTION
    Update a specified User's policy.
     
    .PARAMETER Url
    Base url with domain or IP
     
    .PARAMETER Token
    Bearer Token for the curent endpoint
     
    .PARAMETER UserId
    The ID of the user or the user's email itself.
     
    .PARAMETER GeoBlocking
    Whether to enable geoblocking.
 
    Default value: true
     
    .PARAMETER ArchiveCleanMail
    Whether to store a copy of clean mail in the quarantine for a temporary archive.
 
    Default value: false
     
    .PARAMETER SpamEnabled
    Whether spam filtering is enabled.
     
    .PARAMETER SpamAction
    What to do with a mail marked as spam. Whether to tag and pass it, quarantine it, or reject the mail (delete and send an NDR).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER SpamScore
    The score to determine if a mail is spam. Score for the mail has to be greater than this value to be considered Spam.
    Default value: 5
 
    .PARAMETER SpamSendNdr
    Whether to send an NDR if a mail is quarantined. Only used if the spam_action is quarantine.
    Default value: false
     
    .PARAMETER SpamDiscardScore
    The score to discard the mail at. If the score of the mail is over the spam_discard_score, then the mail will be deleted instead of being quarantined.
    Default value: 999
     
    .PARAMETER SpamAddHeaders
    To include the X-Spam headers to non-spam mails.
    Default value: true
     
    .PARAMETER VirusEnabled
    Whether virus filtering is enabled.
     
    .PARAMETER Sandbox
    Whether or not to send viruses that need sandboxing to the sandbox
     
    .PARAMETER VirusAction
    What to do with a mail marked as a virus. Whether to tag and pass it, quarantine it, or reject the mail (delete the mail).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER AttachmentEnabled
    Whether banned attachment filtering is enabled.
     
    .PARAMETER AttachmentAction
    What to do with a mail marked as a banned attachment. Whether to tag and pass it, quarantine it, or reject the mail (delete the mail).
    Allowed values: quarantine, passtag, reject
     
    .PARAMETER QreportEnabled
    Whether the user should receive a quarantine report for quarantined items.
     
    .PARAMETER QreportLanguage
    The language for the quarantine report to be in
    Default value: en_us
 
    .PARAMETER QreportFrequency
    How often to send the mail.
    Values:
 
        D: Daily
        N: Never
        W: Weekly
        WD: Every Week Day
        M: Monthly
 
    Default value: D
 
    Allowed values: N, D, W, WD, M
     
    .PARAMETER QreportContains
    What quarantine reports contain.
    Values:
 
        A: All items in quarantine.
        N: New items since last report.
        AX: All items except Viruses in Quarantine.
        NX: New items except Viruses since last report.
 
    Default value: N
 
    Allowed values: A, N, AX, NX
     
    .PARAMETER QreportExcludeScore
    The score threshold to exclude mails scoring over it from the quarantine report.
 
    Default value: 999
     
    .EXAMPLE
    PS>$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    PS>$url = "https://Myserver.domain.com"
    PS>Update-STUserPolicy -Url $url -Token $token -UserId "user@example.com" -GeoBlocking
    #>

    [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
    param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Token,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$UserId,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$GeoBlocking,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$ArchiveCleanMail,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$SpamAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamSendNdr,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$SpamDiscardScore,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$SpamAddHeaders,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$VirusEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$Sandbox,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$VirusAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$AttachmentEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("quarantine","passtag","reject")]
        [string]$AttachmentAction,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [switch]$QreportEnabled,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("cs_cz","zh_cn","da_dk","nl_nl","en_us","fr_fr","de_de","he_il","it_it","ja_jp","nb_no","pl_pl","pt_br","ru_ru","es_es","sv_se","th_th","tr_tr")]
        [string]$QreportLanguage,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("D","N","W","WD","M")]
        [string]$QreportFrequency,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [ValidateSet("A","N","AX","NX")]
        [string]$QreportContains,
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [int]$QreportExcludeScore
        
    )
    Begin {
        $endpoint = "/restapi/users"
        [array]$Result = @()
        [hashtable]$body = @{}
    }
    Process {
        if($PSCmdlet.ShouldProcess($Url),"Update User Policy")
        {
            $api = "$($Url)$($endpoint)/$($UserId)/Policy"

            $Header  = @{
                "Accept" = "application/json"
                "Content-Type" = "application/json"
                "Authorization" = "Bearer $($Token)"
            }
            if($PSBoundParameters.ContainsKey("GeoBlocking"))
            {
                $body["geoblocking"] = $GeoBlocking
            }
            if($PSBoundParameters.ContainsKey("ArchiveCleanMail"))
            {
                $body["archive_clean_mail"] = $ArchiveCleanMail
            }
            if($PSBoundParameters.ContainsKey("SpamEnabled"))
            {
                $body["spam_enabled"] = $SpamEnabled
            }
            if($PSBoundParameters.ContainsKey("SpamAction"))
            {
                $body["spam_action"] = $SpamAction
            }
            if($PSBoundParameters.ContainsKey("SpamScore"))
            {
                $body["spam_score"] = $SpamScore
            }
            if($PSBoundParameters.ContainsKey("SpamSendNdr"))
            {
                $body["spam_send_ndr"] = $SpamSendNdr
            }
            if($PSBoundParameters.ContainsKey("SpamDiscardScore"))
            {
                $body["spam_discard_score"] = $SpamDiscardScore
            }
            if($PSBoundParameters.ContainsKey("SpamAddHeaders"))
            {
                $body["spam_add_headers"] = $SpamAddHeaders
            }
            if($PSBoundParameters.ContainsKey("VirusEnabled"))
            {
                $body["virus_enabled"] = $VirusEnabled
            }
            if($PSBoundParameters.ContainsKey("VirusAction"))
            {
                $body["virus_action"] = $VirusAction
            }
            if($PSBoundParameters.ContainsKey("Sandbox"))
            {
                $body["sandbox"] = $Sandbox
            }
            if($PSBoundParameters.ContainsKey("AttachmentEnabled"))
            {
                $body["attachment_enabled"] = $AttachmentEnabled
            }
            if($PSBoundParameters.ContainsKey("AttachmentAction"))
            {
                $body["attachment_action"] = $AttachmentAction
            }
                if($PSBoundParameters.ContainsKey("QreportEnabled"))
            {
                $body["qreport_enabled"] = $QreportEnabled
            }
            if($PSBoundParameters.ContainsKey("QreportLanguage"))
            {
                $body["qreport_language"] = $QreportLanguage
            }
            if($PSBoundParameters.ContainsKey("QreportFrequency"))
            {
                $body["qreport_frequency"] = $QreportFrequency
            }
            if($PSBoundParameters.ContainsKey("QreportContains"))
            {
                $body["qreport_contains"] = $QreportContains
            }
            try{    
                $Result = Invoke-RestMethod -Method Put -Uri $api -Headers $Header -Body $($body|ConvertTo-Json -Depth 99) -ErrorAction Stop
            }
            catch {
                throw $_.Exception.Message
                return $Result
            }
        }
    }
    End {
        return $Result
    }
}
#EndRegion '.\Public\Update-STUserPolicy.ps1' 260