How do I pass variables into a cmd.script?
Description of Issue/Question
I'm trying to follow the salt docs on passing variables into a PowerShell script but nothing seems to work for me :/
I would like to be able to change "Java*" to a different application at will from the command line.
The goal is to get the application and version number from a specific application, but the script has Java hard coded into it. I have to output the results into a CSV so I also need the least amount of text possible.
$application = "Java*"
$applicationList = @()
$applicationList += `
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | `
Where-Object -Property DisplayName -like $application | `
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$applicationList += `
Get-ItemProperty HKLM:\Software\WOW6432node\Microsoft\Windows\CurrentVersion\Uninstall\* | `
Where-Object -Property DisplayName -like $application | `
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
Return $applicationList
I imagine something like:
salt -G os:Windows cmd.script salt://scripts/Applications.ps1 env='{"applications": "Google"}'
First you need to set your scrpt up properly so that it can receive command line arguments. Once it's running from the command line accepting arguments correctly, then you can use args to pass them using salt.
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.cmdmod.html#salt.modules.cmdmod.script
Thanks! I'll give that a try.
That was the hint that I needed! I forgot about needing to have $args[0] in the script, then I just used args='Adobe'* in with the cmd.script module and it worked the first try.
Is there any way to cut out everything but the stdout with cmd.script or is cmd.run_stdout the only way?
I am trying to reduce the noise as much as possible.
Thanks @twangboy