Search code examples
powershellparameter-passingpowershell-3.0psexec

Psexec command to run powershell script with parameters


I am trying to run a powershell script using psexec on a remote machine in TFS2017 as the PowerShell remoting and/or WMI is disabled for security purpose using below script. But i also need to pass some parameters to my powershell script.I have defined these parameters values in the configure variable section of the environment.Not sure how to pass parameters to the powershell script in psexec.

psexec \\computername cmd /c "Powershell.exe D:\script.ps1 -arg $(arg) -arg2 $(arg2) -arg3 $(arg3)" 

But this does not work.Any help would be highly appreciated.


Solution

  • I use something like this. Not much different, but a bypass is in there and I declare -file before the script path.

     psexec \\$computername /s cmd /c %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\path\script.ps1 -parameter1 $blah -parameter2 $blahblah