SpeedTest-CLI.psm1
# Module created by Microsoft.PowerShell.Crescendo class PowerShellCustomFunctionAttribute : System.Attribute { [bool]$RequiresElevation [string]$Source PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } PowerShellCustomFunctionAttribute([bool]$rElevation) { $this.RequiresElevation = $rElevation $this.Source = "Microsoft.PowerShell.Crescendo" } } function Initialize-SpeedTest { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter()] [switch]$Simple, [Parameter()] [switch]$Share, [Parameter()] [switch]$ListServers, [Parameter()] [switch]$ipv4only, [Parameter()] [switch]$ipv6only, [Parameter()] [switch]$CSV, [Parameter()] [int]$Server, [Parameter()] [switch]$NoICMP ) BEGIN { $__PARAMETERMAP = @{ Simple = @{ OriginalName = '--simple' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } Share = @{ OriginalName = '--share' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } ListServers = @{ OriginalName = '--list' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } ipv4only = @{ OriginalName = '--ipv4' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } ipv6only = @{ OriginalName = '--ipv6' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } CSV = @{ OriginalName = '--csv' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } Server = @{ OriginalName = '--server' OriginalPosition = '0' Position = '2147483647' ParameterType = 'int' ApplyToExecutable = $False NoGap = $False } NoICMP = @{ OriginalName = '--no-icmp' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False } } $__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { $pFmt = "{0}{1}" if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } $__commandArgs += $value | Foreach-Object {$_} } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message librespeed-cli.exe $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("librespeed-cli.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "librespeed-cli.exe")) { throw "Cannot find executable 'librespeed-cli.exe'" } if ( $__handlerInfo.StreamOutput ) { & "librespeed-cli.exe" $__commandArgs | & $__handler } else { $result = & "librespeed-cli.exe" $__commandArgs & $__handler $result } } } # end PROCESS <# .SYNOPSIS Incorrect Usage. flag provided but not defined: -? NAME: librespeed-cli - Test your Internet speed with LibreSpeed USAGE: librespeed-cli.exe [global options] [arguments...] GLOBAL OPTIONS: --help, -h show help (default: false) --version Show the version number and exit (default: false) --ipv4, -4 Force IPv4 only (default: false) --ipv6, -6 Force IPv6 only (default: false) --no-download Do not perform download test (default: false) --no-upload Do not perform upload test (default: false) --no-icmp Do not use ICMP ping. ICMP doesn't work well under Linux at this moment, so you might want to disable it (default: false) --concurrent value Concurrent HTTP requests being made (default: 3) --bytes Display values in bytes instead of bits. Does not affect the image generated by --share, nor output from --json or --csv (default: false) --mebibytes Use 1024 bytes as 1 kilobyte instead of 1000 (default: false) --distance value Change distance unit shown in ISP info, use 'mi' for miles, 'km' for kilometres, 'NM' for nautical miles (default: "km") --share Generate and provide a URL to the LibreSpeed.org share results image, not displayed with --csv (default: false) --simple Suppress verbose output, only show basic information (default: false) --csv Suppress verbose output, only show basic information in CSV format. Speeds listed in bit/s and not affected by --bytes (default: false) --csv-delimiter CSV_DELIMITER Single character delimiter (CSV_DELIMITER) to use in CSV output. (default: ",") --csv-header Print CSV headers (default: false) --json Suppress verbose output, only show basic information in JSON format. Speeds listed in bit/s and not affected by --bytes (default: false) --list Display a list of LibreSpeed.org servers (default: false) --server SERVER Specify a SERVER ID to test against. Can be supplied multiple times. Cannot be used with --exclude --exclude EXCLUDE EXCLUDE a server from selection. Can be supplied multiple times. Cannot be used with --server --server-json value Use an alternative server list from remote JSON file --local-json value Use an alternative server list from local JSON file, or read from stdin with "--local-json -". --source SOURCE SOURCE IP address to bind to --timeout TIMEOUT HTTP TIMEOUT in seconds. (default: 15) --duration value Upload and download test duration in seconds (default: 15) --chunks value Chunks to download from server, chunk size depends on server configuration (default: 100) --upload-size value Size of payload being uploaded in KiB (default: 1024) --secure Use HTTPS instead of HTTP when communicating with LibreSpeed.org operated servers (default: false) --skip-cert-verify Skip verifying SSL certificate for HTTPS connections (self-signed certs) (default: false) --no-pre-allocate Do not pre allocate upload data. Pre allocation is enabled by default to improve upload performance. To support systems with insufficient memory, use this option to avoid out of memory errors (default: false) --telemetry-json value Load telemetry server settings from a JSON file. This options overrides --telemetry-level, --telemetry-server, --telemetry-path, and --telemetry-share. Implies --share --telemetry-level value Set telemetry data verbosity, available values are: disabled, basic, full, debug. Implies --share --telemetry-server value Set the telemetry server base URL. Implies --share --telemetry-path value Set the telemetry upload path. Implies --share --telemetry-share value Set the telemetry share link path. Implies --share --telemetry-extra value Send a custom message along with the telemetry results. Implies --share Terminated due to error .DESCRIPTION See help for librespeed-cli.exe .PARAMETER Simple .PARAMETER Share .PARAMETER ListServers .PARAMETER ipv4only .PARAMETER ipv6only .PARAMETER CSV .PARAMETER Server .PARAMETER NoICMP #> } |