Function/System/Start-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
function Start-F2B () {
    <#
    .SYNOPSIS
        Function to Start Fail2Ban Service
    .EXAMPLE
        C:\PS> Start-F2B
    .NOTES
        Author : Thomas ILLIET
        Date : 2018-02-15
        Last Update : 2018-02-15
    #>


    # Check Scheduled Task is exist
    if((Test-F2BScheduledTask -Name 'Fail2Ban-Service') -eq $true) {

        $State = (Get-ScheduledTask -TaskName 'Fail2Ban-Service').State
        if($State -eq 'Ready') {
            Start-ScheduledTask -TaskName 'Fail2Ban-Service'
        } else {
            if($State -eq 'Running') {
                Write-Warning "Scheduled Task (Fail2Ban-Service) already Running"
            } elseif ($State -eq 'Disabled') {
                Write-Error "Scheduled Task (Fail2Ban-Service) is Disabled"
            }
        }
        
    } else {
        Write-Error "Unable to find Scheduled Task (Fail2Ban-Service)"
    }
}