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
Comments
Please sign in to leave a comment.
Mike, I was able to get a powershell command running via a Flow script running on an xAgent.
My script is
The output was a directory listing of the .zip files in my d:\temp folder. Hopefully this gives you something to build your solution on.
Cheers,
Jeremy Brown
I modified the script block slightly to allow variables to be passed to powershell:
(Note the requirement to escape backslashes and asterisks in the argument list.)
(Note also that the comment block requires a newline after your command - before the closing "*/" - or else the command won't be executed.)
@Jeremy,
Thanks for that feedback. Not quite what I am trying to do but close enough to give me some ideas which did work. Your ran a Windows command with arguments using PowerShell to execute it. I was trying to use PowerShell to execute a PowerShell script with arguments.
Using the same type of example I started with in my first post, and tweaking it based on what I learned from your reply, here is what I came up with that does work:
A few things I learned along the way in hopes they will help others: