Embedded PowerShell Scripts
› Forums › Desktop Info › Embedded PowerShell Scripts
Tagged: powershell arguments
- This topic has 6 replies, 2 voices, and was last updated 6 months ago by
Nathan_K.
-
AuthorPosts
-
-
21 July, 2022 at 5:52 am #5427
Hey Glenn,
I’m trying to use the SET-CONTENT feature to pull a script inside of the INI, but I can’t seem to pass an argument to the embedded script like I can with an external call. Any thoughts?
Thanks!
-
21 July, 2022 at 6:02 am #5428
you can’t just add it to the parameters option?
-
22 July, 2022 at 10:53 pm #5431
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:
-
22 July, 2022 at 10:54 pm #5433
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)"} -
25 July, 2022 at 12:26 pm #5435
This has taken me all day to figure out!! I must be getting old 😐
I’m adding one extra user variable before the CMD which contains the query type LOCAL FIXED or REMOVABLE. This is referenced inside the actual embedded script.
INI123SET-SECTION=key:bitlocker-status,value:bitlocker-status.ps1SET=key:script_query,value:LOCAL FIXEDCMD=interval:10,text:Local Fixed Disks,read-as-csv:1,csv-header:1,file:powershell.exe,parameters:%bitlocker-status%,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 user variable is added to the embedded script:
PowerShell123$query='%script_query%'If ( -not $query ) { Exit 1 }...the rest of the script requires you to get the quote characters correct. For the most part, the single quote character seems to work. Hopefully the following code displays correctly on the forum:
PowerShell1234567891011121314151617181920212223242526272829303132[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"$query='%script_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)}-
This reply was modified 6 months ago by
Glenn.
-
This reply was modified 6 months ago by
Glenn.
-
This reply was modified 6 months ago by
Glenn.
-
This reply was modified 6 months ago by
-
25 July, 2022 at 4:08 pm #5438
-
26 July, 2022 at 12:03 am #5441
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.
-
-
AuthorPosts
- You must be logged in to reply to this topic.