Nathan_K
Forum Replies Created
-
AuthorPosts
-
Try adding double-quotes to the output in the PowerShell script like shown in the attachment.
Attachments:
See the attached for my current code, in case you have any variances you are wondering about.
Attachments:
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.
-NathanWas 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.
Insert the following block in between the If and where it starts defining variables.
123For ( $i = 0; $i -lt $wifi_status.Count; $i++ ) {If ( [string]::IsNullOrEmpty($wifi_status[$i]) ) { $wifi_status[$i] = 'n/a' }}Thanks Glenn.. I had made several revisions to the original PS1 since posting, so here’s the updated version as a block that works inside the .ini file.
123456789101112131415161718192021222324[wan-ip-lookup.ps1]## v1.0 -- Retrieve IPv4, IPv6 and Reverse DNS for IPv4## v1.1 -- Updated to use Invoke-RestMethod instead of Invoke-WebRequest## v1.2 -- Added secondary Uri for IPv4 and IPv6## Output headersWrite-Host wan_ipv4 ',' wan_rdns ',' wan_ipv6Try { $IPv4_addr = (Invoke-RestMethod -Uri https://ip4.seeip.org/ -UseBasicParsing -ErrorAction "Stop") }Catch { Try { $IPv4_addr = (Invoke-RestMethod -Uri https://4.tnedi.me/ -UseBasicParsing -ErrorAction "Stop") }Catch { $IPv4_addr = 'n/a' }}Try { $IPv6_addr = (Invoke-RestMethod -Uri https://ip6.seeip.org/ -UseBasicParsing -ErrorAction "Stop") }Catch { Try { $IPv6_addr = (Invoke-RestMethod -Uri https://6.tnedi.me/ -UseBasicParsing -ErrorAction "Stop") }Catch { $IPv6_addr = 'n/a' }}Try {$IPv4_rdns = (Invoke-RestMethod -Uri https://ipinfo.io/$IPv4_addr/hostname -UseBasicParsing -ErrorAction "Stop").Trim()If ( -not $IPv4_rdns ) { $IPv4_rdns = 'No record found' }}Catch { $IPv4_rdns = 'n/a' }Write-Host $IPv4_addr ',' $IPv4_rdns ',' $IPv6_addrExit 01234SET-SECTION=key:wan-ip-lookup,value:wan-ip-lookup.ps1CMD=interval:120,color:55cc77,text:WAN Address,read-as-csv:1,csv-header:1,file:powershell.exe, \parameters:-Command %wan-ip-lookup%,trim:1,show-window:0,hide-no-result:1, \display:{{{IPv4: %1}}}{{{ IPv6: %3}}}{{{ |Reverse DNS: %2}}}I think most of my issues were the single vs double quotes. I did figure out how to set the query inline as well.
parameters:-Command "& {$query='Local Fixed'; %bitlocker-status%}"
That seems to work correctly.
Here is my “SET-SECTION” block.
12SET-SECTION=key:bitlocker-status,value:bitlocker-status.ps1CMD=interval:10,text:Local Fixed Disks,read-as-csv:1,csv-header:1,file:powershell.exe,parameters:%bitlocker-status% -query "Local Fixed",trim:1,show-window:0,color:ffbb77,chart:bar2 scale:linear max:100 series1:{{((%Size%-%FreeSpace%)/%Size%)*100}} threshold:90 0000FF,hide-no-result:1,display:%Name% {{%Size%-%FreeSpace%}}[1.0b]B / {{%Size%}}[1.0b]B ({{((%Size%-%FreeSpace%)/%Size%)*100}}[1.0d]% used) %chart%| BitLocker Status: %BitLocker%and
1234567891011121314151617181920212223242526272829303132[bitlocker-status.ps1]## Get BitLocker drive status for DesktopInfo## Does NOT require Admin rights#### To work properly, PowerShell Execution Policy must be set to RemoteSigned.#### Get arguments for Local or Removable## Valid parameters are "Local Fixed" or "Removable"param ($query)If ( -not $query ) { Exit 1 }## set status values$blStatusDesc = @([pscustomobject]@{desc='Status Unknown'}[pscustomobject]@{desc='Fully Encrypted'}[pscustomobject]@{desc='Unencrypted'}[pscustomobject]@{desc='Encryption in Progress'}[pscustomobject]@{desc='Decryption in Progress'}[pscustomobject]@{desc='Encryption Suspended'}[pscustomobject]@{desc='Decryption Suspended'})## Output headersWrite-Host 'Name, Size, FreeSpace, BitLocker'## get local volumes using WMIForEach ( $logicalVol in (Get-CimInstance -Class Win32_LogicalDisk | Where-Object Description -like "$query*") ) {$blStatus=(New-Object -ComObject Shell.Application).NameSpace($($logicalVol.Name)).Self.ExtendedProperty('System.Volume.BitLockerProtection')Write-Host "$($logicalVol.Name), $($logicalVol.Size), $($logicalVol.FreeSpace), $($blStatusDesc[$blStatus].desc)"}Here is my code block from the config. You can see the result in the attached screenshot.
CMD=interval:10,text:Local Fixed Disks,read-as-csv:1,csv-header:1,file:powershell.exe,parameters:.\scripts\BitLocker-Status.ps1 -query "Local Fixed",trim:1,show-window:0,color:ffbb77,chart:bar2 scale:linear max:100 series1:{{((%Size%-%FreeSpace%)/%Size%)*100}} threshold:90 0000FF,hide-no-result:1,display:%Name% {{%Size%-%FreeSpace%}}[1.0b]B / {{%Size%}}[1.0b]B ({{((%Size%-%FreeSpace%)/%Size%)*100}}[1.0d]% used) %chart%| BitLocker Status: %BitLocker%
That calls the external PS1. If I use the same line and replace the PS1 with my SET-SECTION variable, I get no output data. If I hard code “Local Fixed” into the PS block, I get all bad data.
Attachments:
Windows 2012 R2 doesn’t have that key. It wasn’t introduced until Windows 10 and even then not until 20H2. Before then, the ReleaseID key was used, which works fine in 2016 and 2019, but 2012 R2 doesn’t have that key either. I expected that since both keys are absent it would just mark it as “null” (or whatever value triggers the triple braces to work).
Attachments:
-
AuthorPosts