[Utility] Making Sure PowerShell Scripts for Blue Iris 'Run a program' Actions are PS5.1-Ready

Nov 9, 2016
1,766
1,870
SF Bay Area
I've created a Powershell script to test your PowerShell scripts for their readiness to be safely executed via Blue Iris Blue Iris Action Set 'Run a program' Actions.

One major cause of PS scripts failure to execute from the background via a BI 'Run a program' action is the presence of (some) Non-ASCII characters in the code.
These can silently terminate PS 5.1 depending on the encoding of the script. And a major source of these characters is ChatGPT. ChatGPT slips them into comments, Write-Host commands, and like.
They have caused me grief a number of times!! The most common culprits are em and en dashes. (And before you tell me that, if I ask, ChatGPT will remember my preferences for coding, formats, etc., it clearly has amnesia for some requests).

Just for reference, PS5.1 is the version of PowerShell that is used when you use 'powershell.exe' as the program in a Blue Iris Action Set 'Run a program' Action.
Tip: As a surrogate for background execution, you can always try executing your script from PowerShell-ISE.​
Perhaps ironically, I've used ChatGPT to extend the script for other code elements that might break PS5.1. The entire list now includes:
  • First parse error (Parser:: ParseFile)
  • Non-ASCII characters (which can break PS 5.1 depending on encoding)
  • Literal .Split('|') calls (| can parse as pipeline in PS 5.1)
  • Lines ending with a backtick (line-continuation) that can cause leaks
  • Likely risky encodings (no BOM + non-ASCII bytes)
(Being consistent, it inserted non-ASCII characters during the process :p )​
My experience using the script (for many months now) is that NOT every one of the issues it flags will actually kill the Blue Iris Action, but it's helpful starting point for debugging the script when all else fails. (In particular, I've yet to experience and issue with trailing backticks.)​

IMPORTANT: The script is intended only to be used directly from the PowerShell console.

The basic command is simple
test_ps51_ready.ps1 -Path "C:\ps_scripts\test_bi_overlay_reg_key.ps1"

attachment_1.png

For more concise output
test_ps51_ready.ps1 -Path "C:\ps_scripts\test_bi_overlay_reg_key.ps1" -Raw

attachment_2.png

To test all scripts in an entire folder, or use a wildcard to test a subset of files
test_ps51_ready.ps1 -Path "C:\ps_scripts"
test_ps51_ready.ps1 -Path "C:\ps_scripts\test*.ps1"

attachment_3.png

For more features and explanations, use the -Help argument
test_ps51_ready.ps1 -Help

attachment_4.png

INSTALLATION INSTRUCTIONS
  1. Extract the *.ps1 file from the attached zip file to your desktop, or scripts folder.
  2. Please note that the folder used must be in your PC's environment PATH.
NOTE: If you've never used PowerShell on your Blue Iris PC, you may first to need to change its default security policy.
Open PowerShell in Administrator mode, and type the following, then hit the Enter key: Set-ExecutionPolicy RemoteSigned
(click here for a nice beginner's tutorial to using PowerShell).
 

Attachments

Last edited: