iPerf RMM Automation Powershell

###
# Author: Dave Long <[email protected]>
# Gets an bandwidth test using iPerf3. Sum is the download speed of computer.
###

$client = "TAUL7053"
$iPerfDownload = "https://iperf.fr/download/windows/iperf-3.1.3-win64.zip"
$psexecDownload = "https://download.sysinternals.com/files/PSTools.zip"
$iperfDownloadLocation = Join-Path $env:TEMP "iperf.zip"
$psxecDownloadLocation = Join-Path $env:TEMP "PSTools.zip"
$iPerfPath = Join-Path $env:TEMP "iperf"
$psexecPath = Join-Path $env:TEMP "PSTools"

#download and extract iPerf
if (!(Test-Path $iPerfPath)) {
Invoke-WebRequest -Uri $iPerfDownload -OutFile $iperfDownloadLocation
Expand-Archive -Path $iperfDownloadLocation -DestinationPath $iPerfPath
}

#download and extract psexec
if (!(Test-Path $psexecPath)) {
Invoke-WebRequest -Uri $psexecDownload -OutFile $psxecDownloadLocation
Expand-Archive -Path $psxecDownloadLocation -DestinationPath $psexecPath
}


#create temp directory
#null to stop output
$null = New-Item -Path \\$client\c$\Temp -type directory -Force

Set-Location (Join-Path $iPerfPath "iperf-3.1.3-win64")

#copy iperf3 to client temp
Copy-Item -Path 'iperf3.exe' -Destination \\$client\c$\Temp
Copy-Item -Path 'cygwin1.dll' -Destination \\$client\c$\Temp


#start iperf server for download
#You can use -P option for limiting the incoming clients. For example if you run iperf -s -P 1 command, after the client finishes the test, the server shuts itself down.
Start-Process -Filepath "$psexecPath\psexec.exe" -ArgumentList "\\$client c:\Temp\iperf3.exe -s -1"

#Wait to get iperfstartedonServer
Start-Sleep -Seconds 30

Write-Host "Starting Download Test"
$Download = & .\iperf3.exe --client $client -P 10 -t 60 -w 3M
if (($Download | Select-Object -Last 1) -eq "iperf Done.") {
$sender = $Download | Select-Object -Last 4 | Select-Object -First 2 | Select-Object -First 1
$sender = [regex]::Matches($sender, '\d+\sMbits[/]sec').Value
$sender = $sender -replace " Mbits/sec",""
#in Mbits/sec
$sender

$receiver = $Download | Select-Object -Last 4 | Select-Object -First 2 | Select-Object -Last 1
$receiver = [regex]::Matches($receiver, '\d+\sMbits[/]sec').Value
$receiver = $receiver -replace " Mbits/sec",""
#in Mbits/sec
$receiver
} else {
Write-Host "iPerf failed to get download speed."
}
iPerf RMM Automation Powershell
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...