guyrleech

Turn netsh wifi data into PowerShell object

Apr 29th, 2021 (edited)
1,584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Parse netsh output like this into a hashtable so can easily use in scripts, etc
  2. #   Transmit rate (Mbps)   : 57.8
  3. [hashtable]$wlan = @{};netsh.exe wlan show interfaces | ForEach-Object{ if( $_ -match '(\w[^:]+):\s+?(\w.*)$' -and ! [string]::IsNullOrEmpty( $matches[2] ) ) { $wlan.Add( $matches[1].Trim() , $matches[2] )}}
  4.  
  5. # Using the above to implement a signal strength monitor that updates every 5 seconds
  6. While($true){ [hashtable]$wlan = @{};netsh.exe wlan show interfaces | ForEach-Object{ if( $_ -match '(\w[^:]+):\s+?(\w.*)$' -and ! [string]::IsNullOrEmpty( $matches[2] ) ) { $wlan.Add( $matches[1].Trim() , $matches[2] )}} ; "{0} {1} {2:4} {3}" -f (Get-Date -Format G) , $wlan.SSID , $wlan.Signal , ( "$([char]4)" * [int]($wlan.Signal -replace '%') ) ; start-sleep 5 }
Add Comment
Please, Sign In to add comment