Private/Helper/Start-iPerf.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Start-iPerf {
    <#
    .SYNOPSIS
    Runs iPerf3 to test network performance.
 
    .DESCRIPTION
    This function runs iPerf3 in either server or client mode to test network performance between devices.
 
    .PARAMETER EXEPath
    The path to the iPerf3 executable. Default is "$ModuleUtilityDir\iPerf\iPerf3.exe".
 
    .PARAMETER StartServer
    Switch to start iPerf3 in server mode.
 
    .PARAMETER ServerAddress
    The address of the iPerf3 server to connect to for testing.
 
    .EXAMPLE
    Start-iPerf -StartServer
 
    .EXAMPLE
    Start-iPerf -ServerAddress "192.168.1.1"
 
    .NOTES
    The function checks for the iPerf3 executable and downloads it if necessary. It can run iPerf3 in server mode or connect to a specified server address for testing.
    #>


    [CmdletBinding(DefaultParameterSetName='ServerAddress')] 
    PARAM (
        [Parameter(ParameterSetName = 'StartServer')]
        [Parameter(ParameterSetName = 'ServerAddress')]
        [String]$EXEPath = "$ModuleUtilityDir\iPerf\iPerf3.exe",

        [Parameter(ParameterSetName = 'StartServer')]
        [Switch]$StartServer = $False,

        [Parameter(Mandatory, ParameterSetName = 'ServerAddress')]
        [String]$ServerAddress = ""
    )
    
    ### Check for iPerf3 App
    IF (Test-IntegrisFileDependency -RootPath "$ModuleUtilityDir\iPerf" -ChildPath "\iperf3.exe" -DownloadURL "https://github.com/ar51an/iperf3-win-builds/releases/download/3.17.1/iperf-3.17.1-win64.zip" -Unzip -Confirm) { RETURN }

    IF ($StartServer -eq $True) {
        Write-Host ""
        Write-Host "Running iPerf3 in Server Mode"
        Write-Host "Run Start-iPerf -ServerAddress $($IPs) on another device to run a network speed test."

        Write-Host "iPerf3 Server is Running, Press CTRL+C to Exit..."
        & "$ModuleUtilityDir\iPerf\iPerf3.exe" -s 
    }

    IF ($ServerAddress -ne "") {
        & "$ModuleUtilityDir\iPerf\iPerf3.exe" -c $ServerAddress 
    }
}