Need alternative for netsh wlan show interfaces

Hi Community,

We are using the following powershell script to retreive the wifi information:

$interfaceInfo = netsh wlan show interfaces
		$stateLine = $interfaceInfo -match "State" | Select-Object -First 1
		$state = ($stateLine -split ':\s+')[-1].Trim()
		if ($state -eq "connected") {
			# Extract signal strength
			$signalStrengthLine = $interfaceInfo -match "Signal" | Select-Object -First 1
			[double]$signalStrengthPercent = if ($signalStrengthLine) { ([regex]::Matches((($signalStrengthLine -split ':\s+')[-1].Trim()), '[0-9]+')).Value } else { $null }
			# Extract receive rate
			$receiveRateLine = $interfaceInfo -match "Receive rate" | Select-Object -First 1
			$receiveRate = if ($receiveRateLine) { [int64](($receiveRateLine -split ':\s+')[-1].Trim())*1024*1024 } else { $null }
			# Extract transmit rate
			$transmitRateLine = $interfaceInfo -match "Transmit rate" | Select-Object -First 1
			$transmitRate = if ($transmitRateLine) { [int64](($transmitRateLine -split ':\s+')[-1].Trim())*1024*1024 } else { $null }
			# Extract SSID
			$ssidLine = $interfaceInfo -match "SSID" | Select-Object -First 1
			$ssid = if ($ssidLine) { ($ssidLine -split ':\s+')[-1].Trim() } else { $null }
			# Extract BSSID
			$bssidLine = $interfaceInfo -match "BSSID" | Select-Object -First 1
			$bssid = if ($bssidLine) { ($bssidLine -split ':\s+')[-1].Trim() } else { $null }
			# Extract band
			$bandLine = $interfaceInfo -match "Band" | Select-Object -First 1
			$band = if ($bandLine) { [int64]([double](($bandLine -split ':\s+')[-1].Split(" ")[0].Trim())*1000) } else { $null }
			$jsonObjects = [ordered]@{
					"signal_strength_percent" = $signalStrengthPercent
					"receive_rate_byte_per_sec" = $receiveRate 
					"transmit_rate_byte_per_sec" = $transmitRate
					"ssid" = $ssid  
					"bssid" = $bssid
					"band_mhz" = $band
				}

When the language of the system is different , this command fails.
if ($state -eq “connected”)

Is there any generic solution which should be independent of language ?

I don’t believe so. You’ll want to retrieve the name property from Get-Culture and have a switch statement to set the equivalent “connected” string per language.

Is there a chance that the script runs on a system, where you don’t know the language in advance? :thinking:

Have you tried …

1 Like