Page 1 of 1

Execute command - PowerShell

Posted: Mon Jan 23, 2012 8:27 am
by kriswilliams
Hi Guys,



Has anyone had any luck using the execute command element to run a PowerShell script?



EG.



Command path:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe



Arguments:

"C:ScriptsPowerShellReadXML.ps1"



Can see it execute powershell.exe in the task manager but nothing else happens.



Runs fine if you paste it into a command prompt.



Cheers,

Kris



Execute command - PowerShell

Posted: Mon Jan 23, 2012 12:09 pm
by rzacherl
Hi Kris,



do you refer to any environment variables within your PowerShell code?



Have you already activated Switch logging in debug mode (within the application preferences)? What log messages to you get when the this mode is activated?



Regards,



Robert

Execute command - PowerShell

Posted: Tue Jan 24, 2012 7:08 am
by kriswilliams
Hi Robert,



Thanks for the reply.



There are no enviroment variables in the script. Basically it is used to read in an xml file genereated by a web service, find the url for an image/s, then download that image/s and then compress them into a zip folder.



In the debug logs I get the following:



Message: arguments [-command c:scriptspowershellreadxml.ps1]

Message: executing [powershell -command C:scriptspowershellreadxml.ps1]



At that point it does nothing else.



Ideally I would like to have switch read an xml file that contains the url for the webservice, pass this though to the powershell script ect.



Though on my trial edition, I only seem able to read XMP data.



Cheers,

Kris

Execute command - PowerShell

Posted: Tue Jan 24, 2012 8:20 am
by rzacherl
Hi Kris,



I'm primarily a Mac user. So I have some experience with Windows, little experience with it's standard shell CMD and no experience at all with PowerShell. But looking at the command line options offered by PowerShell shouldn't your argument for the Switch Execute command look like that?



-PCConsoleFile "C:scriptspowershellreadxml.ps1" (if it's a console file)



or



-File "C:scriptspowershellreadxml.ps1"





Regards,



Robert

Execute command - PowerShell

Posted: Mon Feb 18, 2013 2:24 pm
by Jgandersen
Hello

Does anyone have solved this problem here, and if there is what is the solution? :-D

Execute command - PowerShell

Posted: Wed Oct 01, 2014 10:41 am
by sander
We only have Enfocus Switch for a couple of weeks now. This was one of my first issues. Sure this is an old topic, but we should be able to Google everything right? ;)



Managed to get it working with this (running Switch 12u2);



Command or path:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe



Arguments:

-NoLogo -WindowStyle hidden -executionpolicy bypass -file D:FlowsScript.ps1 -ExcelFile "%1"



-ExcelFile is a self defined parameter in my script, but just showing so you know how to use the %1,%2,%3 variables from switch.

Execute command - PowerShell

Posted: Wed Oct 01, 2014 11:54 am
by freddyp
I usually recommend not to run the EXE/app directly, but to use a BAT file/shell script. So in the "Command or path" property you select the BAT file/shell script, you pass the parameters that are variable and you put all the rest in the BAT file/shell script.



There are two reasons why I recommend this. First, it keeps the "Arguments" property cleaner and easier to read. Second, the EXE/app in "Execute command" is running in a different environment than when used in a command prompt/Terminal window and it is sometimes necessary to define certain environment variables to get it to work.



Freddy

Execute command - PowerShell

Posted: Wed Oct 01, 2014 3:44 pm
by gabrielp
sander wrote: We only have Enfocus Switch for a couple of weeks now. This was one of my first issues.
Thank you for sharing your solution