Function/Firewall/Test-F2BFirewallRule.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Test-F2BFirewallRule(){
    <#
    .SYNOPSIS
        . Verifies a firewall rule according to the input parameters
    .PARAMETER IP
        . IP addresses
    .EXAMPLE
        C:\PS> Test-F2BFirewallRule -IP 1.2.3.4
    .NOTES
        Author : Thomas ILLIET
        Date : 2018-02-15
        Last Update : 2018-02-15
    #>

    Param(
        [Parameter(Mandatory=$true)]
        [IpAddress]$IP
    )
    Try {
        $CheckFirewallRule = Get-NetFirewallRule -DisplayName "Fail2Ban - Block $IP" -ErrorAction SilentlyContinue
        if($CheckFirewallRule -ne $null) {
            return $true
        } else {
            return $false
        }
    } Catch {
        Write-Error "Unable to Test Firewall Rule : $_"
        return $false
    }
}