You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Azure DevOps PowerShell任务直接执行指定PS1文件而非生成临时文件

问题

在Azure DevOps YAML中执行PowerShell@2任务时,已通过filePath指定自定义PS1文件路径,但系统仍会在_temp目录生成随机命名的PS1文件。由于公司安全策略不允许将整个_temp文件夹加入白名单放行这些文件,请问是否有办法强制Azure DevOps直接执行指定的PS1文件?

任务配置如下:

steps:
- task: PowerShell@2
  inputs:
    targetType: 'filePath'
    filePath: D:\Apps\myagent\Script\sendEmail.ps1
解决方案
  • 改用内联脚本直接调用目标PS1文件
    放弃filePath模式,切换为targetType: 'inline',直接在脚本块中执行指定的PS1文件,这种方式不会触发中转脚本生成。配置示例:

    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          & "D:\Apps\myagent\Script\sendEmail.ps1"
    
  • 使用CmdLine任务替代PowerShell任务
    直接通过命令行任务调用PowerShell执行脚本,绕开PowerShell@2任务的中转逻辑:

    steps:
    - task: CmdLine@2
      inputs:
        script: |
          powershell -ExecutionPolicy Bypass -File "D:\Apps\myagent\Script\sendEmail.ps1"
    

    可根据实际需求调整ExecutionPolicy参数,确保脚本符合安全策略要求。

  • 自定义Agent任务(进阶方案)
    若上述方法无法满足需求,可自行开发简单的自定义Agent任务,直接调用指定PS1文件,完全跳过Azure DevOps内置PowerShell任务的中转逻辑。自定义任务可部署到本地Agent或通过Azure DevOps扩展市场发布。

内容的提问来源于stack exchange,提问作者stack dev list

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:33:10