Function/System/Enable-F2B.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
30
31
32
33
34
35
36
37
38
39
function Enable-F2B(){
    <#
    .SYNOPSIS
        .
    .EXAMPLE
        C:\PS> Enable-F2B
    .NOTES
        Author : Thomas ILLIET
        Date : 2018-02-15
        Last Update : 2018-02-15
    #>

    
    Write-Debug "# Enable Fail2ban"

    $Task = Get-ScheduledTask -TaskName Fail2ban -ErrorAction SilentlyContinue
    if($Task -ne $null) {
        if($Task.State -eq 'Disabled'){
            Try {
                Disable-ScheduledTask -TaskName Fail2ban
                return $true
            } Catch {
                Write-Error "Unable to disable Fail2ban scheduled task : $_"
                return $false
            }
        } else {
            if($Task.State -eq 'Ready'){
                write-debug ""
                return $true
            } else {
                Write-Error ""
                return $false
            }
        }
    } else {
        Write-Error ""
        return $false
    }

}