iPerf / Powershell – Server and Client Scripts

Use these scripts to start iperf as a client or server.

https://iperf.fr/

Client:

#Variables
    $logPath = "$($env:USERPROFILE)\Desktop\IPERF-Tests\"
    $time = (Get-Date -Format yyy-mm-dd-Hmmss)

#--- LOG File locations
    #--- IF PATH DOES NOT EXIST, CREATE IT
    if(!(Test-Path -Path $logPath )){
        New-Item -Force -ItemType directory -Path $logPath
    }


#Script
Clear-Host

$serverip = Read-Host -Prompt 'Server IP running IPERF '

$timetotransmit = Read-Host -Prompt ' Time to transmit (in seconds) [10] '
        if($timetotransmit -eq $null){ $timetotransmit = "10" }
        if($timetotransmit -eq ""){ $timetotransmit = "10" }

$lengthofbuffer = Read-Host -Prompt ' Length of Buffer (Recommend 128K for TCP, 8K for UDP) [128K] '
        if($lengthofbuffer -eq $null){ $lengthofbuffer = "128K" }
        if($lengthofbuffer -eq ""){ $lengthofbuffer = "128K" }


#-- CHOOSE TO RESOLVE HOSTNAME
    $title = ""
    $message = " Use UDP instead of TCP?"
    $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
        ""
    $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
        ""
    $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
    $result = $host.ui.PromptForChoice($title, $message, $options, 0)


$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $logPath$time.txt -append

cd $env:LAUNCHPADPATH\bin\iperf\


switch ($result)
    {
        0 {
            do {
            Write-Host "Command to run: iperf3.exe -c $serverip -u -t $timetotransmit -l $lengthofbuffer"
            pause
            .\iperf3.exe -c $serverip -u -t $timetotransmit -l $lengthofbuffer
            } until ( $checkFile -match "exit" )
        }

        1 {
            do {
            Write-Host "Command to run: iperf3.exe -c $serverip -u -t $timetotransmit -l $lengthofbuffer"
            pause
            .\iperf3.exe -c $serverip -t $timetotransmit -l $lengthofbuffer
            } until ( $checkFile -match "exit" )
        }
    }



Stop-Transcript

if((Test-Path $logPath$time.txt )){
    ii $logPath$time.txt
}

Server:

#Variables
    $logPath = "$($env:USERPROFILE)\Desktop\IPERF-Tests\"
    $time = (Get-Date -Format yyy-mm-dd-Hmmss)

#--- LOG File locations
    #--- IF PATH DOES NOT EXIST, CREATE IT
    if(!(Test-Path -Path $logPath )){
        New-Item -Force -ItemType directory -Path $logPath
    }


#Script
Clear-Host

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $logPath$time.txt -append -Verbose

cd $env:LAUNCHPADPATH\bin\iperf\
.\iperf3.exe -s -V -d

Stop-Transcript

if((Test-Path $logPath$time.txt )){
    ii $logPath$time.txt
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *