PowerShell command from ScenarioBuilder

Has anyone had any luck running a PowerShell command from the “Run Command Line” action in ScenarioBuilder? The documentation says it’s the same functionality as Start > Run in WIndows. I can paste in the following in Start > Run and it works, the PowerShell script runs and inserts a record into a database table:

cmd /c “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\AppsWatch\AW_SQLCMD.ps1 -ScenarioName JWTESTCMD -Status Success -Debug On”

But when I type the same thing into a Run Command Line action the script tries to run and fails. In the debug log file I get the error:

Could not load file or assembly ‘Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.

Any thoughts?
Thanks,
Jim

@jwiencek Hi Jim,

If your script works successfully in Windows command. Then you can try to run the PowerShell script from a batch file and play the bat file from “Run Command Line” action in ScenarioBuilder.

2 Likes

@jwiencek This error can happen because of a missing Visual C++ Redistributable package. Did you run it in ScenarioBuilder in the same machine that works using cmd?

I did. I can run the script from cmd and also from Start > Run. The only place I get that message is if I try to run it from the ScenarioBuilder “Run Command Line” action. That’s what doesn’t make sense. How can it be a missing C++ package if it works from CMD? My only thought is if that’s the case maybe ScenarioBuilder can’t see the package for some reason.

Thank you amit_singh. I actually did try that and it works, except I was having some trouble passing the string message variable in. I was hoping to avoid that extra step but it may end up being the work around if I can’t resolve the error.

1 Like

Hey Jim, can you share a screenshot of the “Run Command Line” action and the properties?

I found a post that says that the only cmdlet in the SQLServer powershell module that does not work in a 32 bit environment is the Invoke-Sqlcmd cmdlet, which is of course the one I want to use. So maybe I’m stuck until Automai comes out with a 64 bit ScenarioBuilder and AppsWatch version. I had posted on the community forum and one suggestion (which is actually how I started) was to run a batch file execute the Powershell script from the batch file. I had hoped to avoid the intermediate step, but maybe that’s what I’ll need to do.
Thanks
Jim

@jwiencek Hi Jim,

Welcome to the Community!

Thank you for your input. Our development team is looking into this issue.

Issue resolved. The problem was the PowerShell cmdlet Invoke-Sqlcmd does not work in a 32 bit environment, and that’s exactly what I need to do. The rest of the script actually worked, it was just that one line that failed. Thank you all that responded to my post.

First, running the PowerShell script from a batch file and executing the batch file from ScenarioBuilder worked because it avoided running Invoke-Sqlcmd from a 32 bit app. Here’s the actual command from the Run Command Line action:
C:\AppsWatch\AW_SQLCMD.bat %ScenarioName% %ScenarioStatus% “%ScenarioMessage%”

I tried various options with the development team and what finally worked is a test 64 bit ScenarioBuilder app. Here’s the command from the Run Command Line action:
C:\AppsWatch\AW_SQLCMD.bat %ScenarioName% %ScenarioStatus% “%ScenarioMessage%”

And here’s the command from the Start Application action (which is a little cleaner):
C:\AppsWatch\AW_SQLCMD.bat %ScenarioName% %ScenarioStatus% “%ScenarioMessage%”

Of course all of those presupposes that you have PowerShell and the SQLServer module and permissions set correctly, and that you also have the require 64 bit C++ runtime install.

I believe Automai will be packaging up the 64 bit version and making it available with a future release.

3 Likes

@jwiencek Glad it’s resolved. Good information, thanks for sharing! :+1:t4: