代码之家  ›  专栏  ›  技术社区  ›  hot33331

从任务计划程序启动时PowerShell脚本未完成

  •  0
  • hot33331  · 技术社区  · 7 年前

    我这里有一个PowerShell脚本:

    https://github.com/Azure/azure-devtestlab/blob/master/Artifacts/windows-vsts-download-and-run-script/DownloadVstsDropAndExecuteScript.ps1

    我用来下载VSTS构建工件的。当我在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>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   hot33331    7 年前

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

    $wc = New-Object System.Net.WebClient
        foreach ($key in $Headers.Keys) {
            $wc.Headers.Add($key, $Headers[$key])
        }
        $wc.DownloadFile($downloadUrl, $outfile)
    

    推荐文章