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.