Execute command - PowerShell

Post Reply
kriswilliams
Newbie
Posts: 4
Joined: Fri Jan 06, 2012 6:09 am

Execute command - PowerShell

Post 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


rzacherl
Member
Posts: 36
Joined: Mon Mar 21, 2011 3:29 pm

Execute command - PowerShell

Post 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
kriswilliams
Newbie
Posts: 4
Joined: Fri Jan 06, 2012 6:09 am

Execute command - PowerShell

Post 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
rzacherl
Member
Posts: 36
Joined: Mon Mar 21, 2011 3:29 pm

Execute command - PowerShell

Post 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
Jgandersen
Newbie
Posts: 6
Joined: Tue Sep 13, 2011 4:13 pm

Execute command - PowerShell

Post by Jgandersen »

Hello

Does anyone have solved this problem here, and if there is what is the solution? :-D
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Execute command - PowerShell

Post 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.
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Execute command - PowerShell

Post 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
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Execute command - PowerShell

Post 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
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Post Reply