Azure devops 从任务计划程序启动时,Powershell脚本未完成

Azure devops 从任务计划程序启动时,Powershell脚本未完成,azure-devops,taskscheduler,Azure Devops,Taskscheduler,我在这里有一个powershell脚本: 我用来下载VST构建工件的。当我在powershell中运行脚本时,它工作得非常好。当我像这样在命令提示符下运行它时,它可以完美地工作 powershell.exe -ExecutionPolicy Bypass C:\PathToScript\DownloadVstsDropAndExecuteScript.ps1 -parameters 但是,当我尝试将其作为计划任务运行时,脚本似乎没有完成下载(zip文件大小太小,当我尝试打开时,文件已损坏)。

我在这里有一个powershell脚本:

我用来下载VST构建工件的。当我在powershell中运行脚本时,它工作得非常好。当我像这样在命令提示符下运行它时,它可以完美地工作

powershell.exe -ExecutionPolicy Bypass C:\PathToScript\DownloadVstsDropAndExecuteScript.ps1 -parameters
但是,当我尝试将其作为计划任务运行时,脚本似乎没有完成下载(zip文件大小太小,当我尝试打开时,文件已损坏)。在用户登录模式和未登录用户模式下

任务xml如下所示:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2"     xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-07-17T08:39:31.2909587</Date>
    <Author>LOCALPC\Administrator</Author>
    <URI>\Download Nightly Artifacts</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2018-07-17T04:44:44</StartBoundary>
      <ExecutionTimeLimit>PT2H</ExecutionTimeLimit>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Monday />
          <Tuesday />
          <Wednesday />
          <Thursday />
          <Friday />
          <Saturday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
   </Triggers>
  <Principals>
     <Principal id="Author">
       <UserId>S-1-5-21-1204101111-744349012-1702229681-300</UserId>
       <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
     </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>PT2H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>powershell.exe</Command>
      <Arguments>C:\PathToScript\DownloadVstsDropAndExecuteScript.ps1 -parameters</Arguments>
    </Exec>
  </Actions>
</Task>

2018-07-17T08:39:31.2909587
LOCALPC\管理员
\每晚下载工件
2018-07-17T04:44:44
PT2H
真的
1.
S-1-5-21-1204101111-744349012-1702229681-300
互动电视
高可用性
无知的新
假的
假的
真的
真的
假的
真的
假的
真的
真的
假的
假的
真的
PT2H
7.
父进程
C:\PathToScript\DownloadVstsDropAndExecuteScript.ps1-参数
已更换

Invoke-RestMethod -Uri "$downloadUrl" -Headers $Headers -Method Get -Outfile $outfile | Out-Null


感谢@anheledir提供的解决方案

刚刚做到了:-D@CeceDong MSFT
$wc = New-Object System.Net.WebClient
    foreach ($key in $Headers.Keys) {
        $wc.Headers.Add($key, $Headers[$key])
    }
    $wc.DownloadFile($downloadUrl, $outfile)