0

Running PowerShell Script using xMatters Agent's xm-shell

The only documentation that xMatters provide regarding their xMatters Agent xm-Shell feature is on Running local scripts on the xMatters Agent.  There it talks about, on the server where the xMatters Agent resides, creating a batch file with commands and then running that batch file commands.

I tried to translate this into running a PowerShell script while passing arguments to that script and had no luck.  Here is what I have tried:

// This one seems to start the process without issue but the process doesn't complete.
// var GatherObjectStatus = Shell.script(function () {/* REM #### PLACE YOUR .BAT SCRIPT BETWEEN HERE #####
//     powershell -File "C:\\Coding Library\\PowerShell\\Find Status of Some Object.ps1" "1238233" "Yes"
//     REM ##### AND HERE #### */});
//     //{ID: ObjectId});

// This one also starts the process but it doesn't complete. This version is using ExecutionPolicy.
// var GatherObjectStatus = Shell.script(function () {/* REM #### PLACE YOUR .BAT SCRIPT BETWEEN HERE #####
// powershell -ExecutionPolicy Bypass -File "C:\\Coding Library\\PowerShell\\Find Status of Some Object.ps1" "1238233" "Yes"
// REM ##### AND HERE #### */});
// //{ID: ObjectId});

// This one also starts the process but it doesn't complete. This version is using ${ID}.
// var GatherObjectStatus = Shell.script(function () {/* REM #### PLACE YOUR .BAT SCRIPT BETWEEN HERE #####
// powershell -ExecutionPolicy Bypass -File "C:\\Coding Library\\PowerShell\\Find Status of Some Object.ps1" ${ID} "Yes"
// REM ##### AND HERE #### */},

// Execute it
// var result = Shell.exec('cmd', GatherObjectStatus );

I would also like result to be able to contain more than just if the Shell.exec was successful or not.  For example, run a query against the database while in the PowerShell script and then return the results back to the Step Script to determine how it should proceed.

Do any of you folks that are likely smarter than I, see a way to make this work?

Let me add that I know very little about xm-shell.  If there is a way to run the PowerShell directly without having to put it in a batch file and then run that, I am all ears.  I tried a few things but nothing worked.

TIA

Mike

3 comments

Please sign in to leave a comment.