private/Remove-iPerf3Port.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 Remove-iPerf3Port {
    <#
        .SYNOPSIS
        Removes the local firewall rules for the port that iPerf3 was listening on.

        .DESCRIPTION
        Removes the local firewall rules for the port that iPerf3 was listening on.
        This will remove the configured firewall rules from Windows Firewall.

        .EXAMPLE
        Remove-iPerf3Port
    #>


    [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Medium')]
    Param()

    Write-Verbose -Message 'Removing inbound and outbound iperf3 firewall rules.'

    try {
        if ($PSCmdlet.ShouldProcess('iperf3 Inbound/Outbound Firewall Rules', 'Remove-NetFirewallRule')) {
            Get-NetFirewallRule -DisplayName 'iPerf3 Server Inbound TCP Rule' |
                Remove-NetFirewallRule
            Get-NetFirewallRule -DisplayName 'iPerf3 Server Outbound TCP Rule' |
                Remove-NetFirewallRule
        }
    } catch {
        Write-Verbose -Message 'Firewall rules not found - no action taken.'
    }
}