Running Powershell scripts with command line parameters via Salt cmd.script

3,642 views
Skip to first unread message

Drew Malone

unread,
Jun 13, 2013, 11:17:07 AM6/13/13
to salt-users
Hi there,

We're trying to use the Salt function cmd.script to run Powershell scripts on a Windows box. The scripts run just fine but they are not seeing the command line arguments. We've done some sanity testing with Bash scripts on a Linux box and with a Batch script on the same Windows box. Command line arguments work fine for those.

Our research led us to what we believe is the culprit. When cmd.script executes a script on Windows, it uses the (obvious) default of cmd.exe to launch the script. When we open a cmd.exe shell and try to run our Powershell script, we also fail to pass the parameters to the script.

Here is our (very simple) Powershell script.
"""
Write-Host "I found some text! It's -> $args"
"""

When we run this in a cmd.exe shell:
c:\tmp>test.ps1 donkey

The expected output:
I found some text! It's -> Donkey

The actual output:
I found some text! It's ->

Is there another method we should be using to pass parameters to Powershell scripts or possibly a workaround? We have some time and a need for this feature so, given some guidance on where to start, we may be able to implement this if it's not there yet.

We are using version 0.15.1 of both the Master and the Minion.

Thanks much.

-Drew

David Boucha

unread,
Jun 13, 2013, 12:59:46 PM6/13/13
to salt users list
Ah, I've been meaning to test powershell scripts with the cmd module.

Have you tried using an alternate shell instead of cmd.exe?

There's an option to use an alternate shell in the cmdmod.py   : http://docs.saltstack.com/ref/modules/all/salt.modules.cmdmod.html#salt.modules.cmdmod.script

You might try using the path to the powershell executable.  On Windows server 2008 the path is: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

office 801-305-3563
da...@saltstack.com | www.saltstack.com

Aled

unread,
Aug 29, 2013, 3:38:25 AM8/29/13
to salt-...@googlegroups.com
Hello,
I guess you figured this out by now, but I had the same issue and resolved it by using this format: (adding 'Powershell -File' before command)

salt \win* cmd.run 'powershell -File c:\salt\isserviceinstalled.ps1 server'

Cheers
Reply all
Reply to author
Forward
0 new messages