简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM