SRM/SystemEDGE and PowerShell scripts

Document ID : KB000028869
Last Modified Date : 14/02/2018
Show Technical Document Details

Does SystemEDGE/SRM Custom Tests work with PowerShell scripts?

Yes, it has been successfully used in both SRM Custom Tests AND SystemEDGE MIB Extensions.
In the implementation of PowerShell scripts there are a few known problems that must be addressed before this will be successful.
 1.When using PowerShell scripts the SRM/SystemEDGE log shows:
"This isn`t a valid Win32 application"
This is shown when you call the 64 bit version of PowerShell from a 32 bit application. It can be corrected by calling the 32 bit version of PowerShell to interpret the ps1 script. Or installing the 64 bit version of SystemEDGE on the 64 bit versions of windows (recommended).
Calling PowerShell from a batch file ends in a timeout even though the PowerShell script runs properly when run manually. The batch file exits faster than the PowerShell thus not allowing PowerShell to return and provide output. Calling the PowerShell script with the “start /wait” command makes the batch file wait for the called PowerShell Script to finish before exiting.

1.The PowerShell script must be called in a noninteractive mode and must exit with no user intervention.
 2.You cannot use or reference any user environment variables since the SystemEDGE service runs as system account has no access to this information.
 3.Only the first line of output will be seen by SRM/SystemEDGE. Anything after the first newline will be ignored. When calling custom scripts via SRM, ensure that the output meets the requirements as noted in the SRM User Guide.

Here is the SRM Custom Example of the Batch file:
@echo off
start /wait C:\Windows\SysWOW64\WindowsPowerShell\v1.0\PowerShell.exe -noninteractive -File "C:\hello\test.ps1"

Sample PowerShell only call from SystemEDGE agent: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\PowerShell.exe -noninteractive -File "C:\hello\test.ps1"
Note: “C:\Windows\SysWOW64\WindowsPowerShell\v1.0\PowerShell.exe” is the 32 bit version of PowerShell.


Sample “test.ps1” PowerShell script:
echo "hello"

Sample SRM Watcher direct PowerShell configuration
Assuming 32 or 64 bit OS with matching 2 or 64 bit SystemEDGE and SRM – a 64 bit OS with 32 bit SystemEDGE/SRM will require the 32 bit path to PowerShell as noted previously.
desc="Test custom service"
dest="C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -noninteractive -File "C:\scripts\SRMCustomScript.ps1"" encoded="yes"

Sample SRM Watcher batch calling PowerShell configuration
desc="Test custom service"
dest="C:\Windows\System32\cmd.exe /q /c c:\scripts\PS.bat"
The “c:\scripts\PS.bat” batch file would then call the appropriate script (as noted above):
@echo off
start /wait C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -noninteractive -File "C:\scripts\SRMCustomScript.ps1"
The SRMCustomScript.ps1 script will need to echo proper values per documented requirements:
echo 1 1 1