Jenkins 中的提升 PS 脚本

Pet*_*ter 5 powershell jenkins

我一直在尝试从 Windows Jenkins(从属)服务器运行脚本。该脚本是用 PowerShell 编写的,需要提升权限(例如,如果右键单击 PS 并选择以管理员身份运行)。

Jenkins 通过以下方式启动其脚本:

powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\JOHAN.DER\AppData\Local\Temp\2\hudson9084956499652818911.ps1'" 
Run Code Online (Sandbox Code Playgroud)

我的脚本失败,因为它需要提升的权限。如何生成可以运行我的脚本的新的提升特权的 PS 进程(不需要单击,因为 Jenkins 不能这样做)?

干杯!

Ran*_*tta 0

尝试这个 :

powershell -Command "Start-Process powershell \"-ExecutionPolicy Bypass -NoExit -Command `\"cd \`\"%scriptFolderPath%`\"; & \`\".\%powershellScriptFileName%\`\"`\"\" -Verb RunAs"
Run Code Online (Sandbox Code Playgroud)