Core/Private/Functions.ps1
|
$ScriptBlockSwitchFrequencyChanel = { param ($frequency_mhz) switch ($frequency_mhz) { # 2.4 GHz Band (Kanalen 1–13) { $_ -ge 2412 -and $_ -le 2472 } { return [Int][math]::Floor(($_ - 2412) / 5) + 1 } # 5 GHz Band (Alle segmenten) # Formule: (Freq - 5000) / 5 { $_ -ge 5180 -and $_ -le 5825 } { return [int][math]::Floor(($_ - 5000) / 5) } # 6 GHz Band (Kanalen 1–233) # Formule: (Freq - 5950) / 5 { $_ -ge 5955 -and $_ -le 7115 } { return [int][math]::Floor(($_ - 5950) / 5) } default { return "Out of Range:$($_)" } } } function Get-WifiChannel { param( [parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias("WiFiAvailableNetwork")] [Windows.Devices.WiFi.WiFiAvailableNetwork[]]$WiFiAvailableNetworks, # Single center frequency in kilohertz (optional) [parameter(Mandatory = $False)] [int]$ChannelCenterFrequencyInKilohertz ) process { if ($ChannelCenterFrequencyInKilohertz) { # If a single center frequency is provided, calculate the channel for it return &$ScriptBlockSwitchFrequencyChanel ($ChannelCenterFrequencyInKilohertz / 1000) } else { # If no frequency is provided, loop through Wi-Fi networks foreach ($WiFiAvailableNetwork in $WiFiAvailableNetworks) { # Get the ChannelCenterFrequencyInKilohertz from the current network and convert it to MHz # Call the script block to get the channel number [PSCustomObject]@{ Ssid = $WiFiAvailableNetwork.Ssid WifiBand = (Get-WifiBandName $WiFiAvailableNetwork.ChannelCenterFrequencyInKilohertz) WifiChannel = (&$ScriptBlockSwitchFrequencyChanel ($WiFiAvailableNetwork.ChannelCenterFrequencyInKilohertz / 1000)) NetworkRssiInDecibelMilliwatts = $WiFiAvailableNetwork.NetworkRssiInDecibelMilliwatts } } } } } function Get-WifiBandName { param ([long]$ChannelCenterFrequencyInKilohertz) switch ($ChannelCenterFrequencyInKilohertz) { { $_ -ge 2400000 -and $_ -le 2500000 } { "2.4 GHz"; break } { $_ -ge 5150000 -and $_ -le 5895000 } { "5 GHz"; break } { $_ -ge 5925000 -and $_ -le 7125000 } { "6 GHz"; break } Default { $ghz = [math]::Floor($_ / 100000) / 10 "$ghz GHz" } } } |