1

I am trying to execute a PowerShell script on a salt-minion windows server from a salt master Linux server.

I am sending the command like this:

salt My-server cmd.run "C:\Users\XYZ\Desktop\my_script.ps1" shell=powershell

This works but I need to execute this script as a specific user.

I have tried all of the following:

salt My-server cmd.run "start powershell -credential "XYZ" C:\Users\XYZ\Desktop\my_script.ps1"

salt My-server cmd.run "runas/user:XYZ "powershell.exe C:\Users\XYZ\Desktop\my_script.ps1" 

salt My-server cmd.run "runas/user:XYZ C:\Users\XYZ\Desktop\my_script.ps1" shell=powershell

But all of them either fail to run the script or don't have the desired effect.

I don't know much about PowerShell but I know how to do the same in Linux bash:

su -c "C:\Users\XYZ\Desktop\my_script.ps1" XYZ

I am aware that's not a valid Linux path but you see the point.

0

1 Answer 1

1

Have you tried using the runas option for cmd.run? Such as:

salt My-server cmd.run "C:\Users\XYZ\Desktop\my_script.ps1" runas=XYZ shell=powershell

The documentation seems to imply that password= argument may be required, too:

runas (str) -- Specify an alternate user to run the command. The default
behavior is to run as the user under which Salt is running. If running on 
a Windows minion you must also use the password argument, and the target 
user account must be in the Administrators group.

Documentation references:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.