Public/Start-Iperf.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function Start-Iperf {
    <#
    .DESCRIPTION
    Setup and iperf server or client connection for testing connection speeds

    .PARAMETER server
    Specify if running in server mode

    .PARAMETER client
    Specify if running in client mode

    .PARAMETER udp
    Specify to use udp

    .PARAMETER serverip
    Specify the ip of the server connecting to when in client mode

    .PARAMETER port
    specify the port for the client and server connections

    .EXAMPLE
    Setup a iperf server connection

    Start-Iperf -server -port 10555

    .EXAMPLE
    Initiate a client bandwidth test

    Start-Iperf -client -serverip 0.0.0.0 -port 10555

    .EXAMPLE
    Initiate a client bandwidth test

    Start-Iperf -Client -serverip 0.0.0.0 --port 10555 udp
    #>


    [CmdletBinding()]
    [Alias('iperf')]
    Param (

        [Parameter(Mandatory = $true, ParameterSetName = 'Server')][Switch]$server,
        [Parameter(Mandatory = $true, ParameterSetName = 'Client')][switch]$client,
        [Parameter(Mandatory = $false, ParameterSetName = 'Client')][Switch]$udp,
        [Parameter(Mandatory = $true, ParameterSetName = 'Client')]$serverip,
        [Parameter(Mandatory = $true, ParameterSetName = 'Client')]
        [Parameter(Mandatory = $true, ParameterSetName = 'Server')]
        $port
    )

    $AdminConsole = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")

    if ($AdminConsole -like "False*") {
        Write-Warning "You need to run PowerShell as an admin to use this function!"
        Break
    }

    if ($server) {
        iperf3.exe -s -p $port
    }

    if ($client) {
        if ($udp) {
            iperf3.exe -c $serverip -p $port -u -b 0
        }

        else {
            iperf3.exe -c $serverip -p $port
        }
    }
}