Hey all, thought I'd share this tidbit that I created. It's to display the currently connected WiFi status. Required code bits and a screenshot example are below. Enjoy!
SET-SECTION=key:wifi-status,value:wifi-status.ps1
CMD=interval:120,color:55cc77,text:WiFi Status,onload,no-wait:2,read-as-csv:1,csv-header:1,file:powershell.exe,
parameters:-Command %wifi-status%,trim:1,show-window:0,hide-no-result:1,
display:SSID: %SSID% Encryption: %Auth% / %Cipher%| BaseStation ID: %BSSID% Type: %NetType%| Radio: %Radio% Band: %Band% Channel: %Channel% Signal: %Signal%
[[wifi-status.ps1]
$wifi_status = @( netsh wlan show interfaces ).Replace(' : ',' = ')
$wifi_status = $wifi_status.Split('=').Trim()
If ( -not $wifi_status.Contains('connected') ) { Exit 0 }
$State = $wifi_status[ [Array]::indexOf($wifi_status,'State') + 1 ]
$SSID = $wifi_status[ [Array]::indexOf($wifi_status,'SSID') + 1 ]
$BSSID = $wifi_status[ [Array]::indexOf($wifi_status,'BSSID') + 1 ]
$NetType = $wifi_status[ [Array]::indexOf($wifi_status,'Network type') + 1 ]
$Radio = $wifi_status[ [Array]::indexOf($wifi_status,'Radio type') + 1 ]
$Auth = $wifi_status[ [Array]::indexOf($wifi_status,'Authentication') + 1 ]
$Cipher = $wifi_status[ [Array]::indexOf($wifi_status,'Cipher') + 1 ]
$Band = $wifi_status[ [Array]::indexOf($wifi_status,'Band') + 1 ]
$Channel = $wifi_status[ [Array]::indexOf($wifi_status,'Channel') + 1 ]
$Signal = $wifi_status[ [Array]::indexOf($wifi_status,'Signal') + 1 ]
# Output headers and data
Write-Host State ',' SSID ',' BSSID ',' NetType ',' Radio ',' Auth ',' Cipher ',' Band ',' Channel ',' Signal
Write-Host $State ',' $SSID ',' $BSSID ',' $NetType ',' $Radio ',' $Auth ',' $Cipher ',' $Band ',' $Channel ',' $Signal
Exit 0
Nice! Works well here.
I'm getting no value on the %Signal% variable... Actually, when I run that command on my machine it doesn't show an entry for Band and everything after that on the DTI output is wrong. What's powershell syntax for "if it doesn't exist use this default value" ?
Insert the following block in between the If and where it starts defining variables.
For ( $i = 0; $i -lt $wifi_status.Count; $i++ ) {
If ( [string]::IsNullOrEmpty($wifi_status[$i]) ) { $wifi_status[$i] = 'n/a' }
}
Was doing a little extra looking. The Band (2.4 GHz vs 5 GHz) is displayed in Windows 11, but does not appear to be reported in Windows 10, so that explains why it was blank. It'll just show as "n/a" with the block above. Could also use the triple-brackets to make it not show up I guess.
that works.
Hi Nathan - great tip; Exactly what I wanted; but I can't get it to work. I understand it as follows: Lines 1 to 5 are entered in the desktopinfo.ini in the [Items] area and lines 7 to 27 are saved as a Powershell script, e.g. in the DesktopInfo directory.
The result looks like this (attachment)
what am I doing wrong?
Thanks for a second tip 🙂
Hey Dirk,
I wrote this for the newer versions of DesktopInfo that include embedded PS1 support and do not require external .ps1 files in a scripts folder. The [wifi-status.ps1] block should just be at the bottom of your .ini file and does not need to be in a separate .ps1 file.
Also, all of the "'" need to be a single-quote. The code block in Glenn's forums likes to convert them to html code instead.
Hope that helps.
-Nathan
Thanks for pointing out " ' " <'> - it took me a while to understand the context (I'm not a programmer ;-)) But: it took me even longer to realize why no result was displayed: I had to translate the command line and the parameters - I work with a German PC .... sometimes it can be so easy 🙂 Thank you!!
See the attached for my current code, in case you have any variances you are wondering about.
Hello Nathan, I need your help again. When switching to the 2.4GHz band, the array recognizes the comma (2,4) as a separator and the other values are displayed/read incorrectly. Is there a solution? Please look at the screenshots: Channel 11 is now reported as 11 Mbit/s and the signal strength shows the 65 (Mbit value) as 65%... Thank you for your time.
Try adding double-quotes to the output in the PowerShell script like shown in the attachment.
double quotes didn't help; I got it now with a second "replace". thx, Urmel
Hello alll
So i'm not the greatest coder, I don't know how to "call" a item. The two things I need to display or call are SSID and signal strength. Please Help !
CMD=interval:120, cext: - SSID, onload, no-wait: 2, read-as-csv:1, csv-header: 1, file: powershell.exe, parameters :- Command wifi-status%, trim: 1, show-wifi-status
#CMD-interval: 120, text: - WiFi Status, onload, no-wait:2, read-as-csv:1, csv-header:1, file:powershell. exe, parameters :- Command wifi-statuss, trim:1, show-wifi-status
[wifi-status.ps1]
$wifi_status = @( netsh wlan show interfaces ).Replace(' : ',' = ')
$wifi_status = $wifi_status.Split('=').Trim()
If ( -not $wifi_status.Contains('connected') ) { Exit 0 }
For ( $i = 0; $i -lt $wifi_status.Count; $i++ ) {
If ( [string]: : IsNullOrEmpty($wifi_status[$i]) ) { $wifi_status[$i] = 'n/a' }
$State = $wifi_status[ [Array] :: indexOf($wifi_status, 'State') + 1 ]
$SSID = $wifi_status[ [Array] :: indexOf($wifi_status, 'SSID') + 1 ]
$BSSID = $wifi_status[ [Array] :: indexOf($wifi_status, 'BSSID') + 1 ]
$NetType = $wifi_status[ [Array] :: indexOf($wifi_status, 'Network type') + 1 ]
$Radio = $wifi_status[ [Array] :: indexOf($wifi_status, 'Radio type') + 1 ]
$Auth = $wifi_status[ [Array] :: indexOf($wifi_status, 'Authentication') + 1 ]
$Cipher = $wifi_status[ [Array] :: indexOf($wifi_status, 'Cipher') + 1 ]
$Band = $wifi_status[ [Array] :: indexOf($wifi_status, 'Band') + 1 ]
$Channel = $wifi_status[ [Array] :: indexOf($wifi_status, 'Channel') + 1 ]
$Signal = $wifi_status[ [Array] :: indexOf($wifi_status, 'Signal') + 1 ]
SET-SECTION=key:wifi-status,value:wifi-status.ps1
CMD=interval:120,color:55cc77,text:WiFi Status,onload,no-wait:2,read-as-csv:1,csv-header:1,file:powershell.exe,
parameters:-Command %wifi-status%,trim:1,show-window:0,hide-no-result:1,
display:SSID: %SSID% Encryption: %Auth% / %Cipher%| BaseStation ID: %BSSID% Type: %NetType%| Radio: %Radio% Band: %Band% Channel: %Channel% Signal: %Signal%
A couple of things to note are:
the backslash at the end of a line indicates the current logical line continues on the next physical line. if you want to join these lines together so that an item is on a single physical line then you must remove the backslash.
a replaceable parameter (or variable) is indicated by a percent sign at the beginning and end of a word.
the following inserts the code in the ini section called [wifi-status.ps1] into a variable called %wifi-status%. This section is usually at the end of the file past the [items]
SET-SECTION=key:wifi-status,value:wifi-status.ps1
the next line executes the powershell code contained in %wifi-status% and displays the result.
CMD=interval:120,color:55cc77,text:WiFi Status,wide:1,onload,no-wait:2,read-as-csv:1,csv-header:1,file:powershell.exe, parameters:-Command %wifi-status%,trim:1,show-window:0,hide-no-result:1, display:SSID: %SSID% Encryption: %Auth% / %Cipher%| BaseStation ID: %BSSID% Type: %NetType%| Radio: %Radio% Band: %Band% Channel: %Channel% Signal: %Signal%
this is all a single "item".
I'm not great with powershell but if you copy that entire section verbatim from the desktopinfo-advanced.ini file and paste it at the end of your working ini file, it should be good to go.