Public/Invoke-UnBypassIntrusionZone.ps1

<#
    .SYNOPSIS
    Unbypasses an intrusion zone.
 
    .DESCRIPTION
    Unbypasses an intrusion zone.
 
    If the result returns null, try the parameter "-Verbose" to get more details.
 
    .EXAMPLE
    Invoke-UnBypassIntrusionZone
 
    .LINK
    https://github.com/erwindevreugd/PSDataConduIT
 
    .EXTERNALHELP PSDataConduIT-help.xml
#>

function Invoke-UnBypassIntrusionZone {
    [CmdletBinding()]
    param
    (
        [Parameter(
            Position = 0,
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'The name of the server where the DataConduIT service is running or localhost.')]
        [string]
        $Server = $Script:Server,

        [Parameter(
            Position = 1,
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'The credentials used to authenticate the user to the DataConduIT service.')]
        [PSCredential]
        $Credential = $Script:Credential,

        [Parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'Specifies the id of the intrusion zone to un-bypass.')]
        [int]
        $IntrusionZoneID,

        [Parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $false,
            HelpMessage = 'Returns an object that represents the intrusion zone. By default, this cmdlet does not generate any output.')]
        [switch]
        $PassThru
    )

    process {
        $parameters = @{
            Server = $Server;
        }

        if ($Credential -ne $null) {
            $parameters.Add("Credential", $Credential)
        }

        if (($intrusionZones = Get-IntrusionZone @parameters -IntrusionZoneID $IntrusionZoneID) -eq $null) {
            Write-Verbose -Message ("No intrusion zones found")
            return
        }

        foreach ($intrusionZone in $intrusionZones) {
            $intrusionZone.UnBypass.Invoke() | Out-Null

            Write-Verbose -Message ("Intrusion zone '$($intrusionZone.Name)' unbypassed")

            if ($PassThru) {
                Write-Output $intrusionZone
            }
        }
    }
}