繁体   English   中英

在任务计划程序上运行PowerShell脚本

[英]Running PowerShell Script on Task Scheduler

我在其他问题中查看了有关任务调度程序答案的所有PowerShell脚本,但未能找到解决此问题的脚本。

我尝试使用以下命令直接通过任务计划程序运行PowerShell脚本:

       powershell.exe -file c:\path_to_your_script\script.ps1

以及创建批处理以运行PowerShell脚本。

PowerShell脚本可以完美地查找它自己运行以及手动运行批处理时的情况。

它打开一个excel,刷新,保存和关闭。

我无法通过任务处理程序成功安排此操作。

有什么建议?

谢谢您的帮助

编辑:

@luke这是任务调度程序设置的导出

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
<Date>2015-05-11T12:40:51.6084684</Date>
<Author>----------</Author>
  </RegistrationInfo>
  <Triggers>
 <TimeTrigger>
  <Repetition>
    <Interval>PT1H</Interval>
    <StopAtDurationEnd>false</StopAtDurationEnd>
  </Repetition>
  <StartBoundary>2015-05-11T12:30:00</StartBoundary>
  <Enabled>true</Enabled>
</TimeTrigger>
  </Triggers>
  <Principals>
<Principal id="Author">
  <UserId>------\Administrator</UserId>
  <LogonType>Password</LogonType>
  <RunLevel>HighestAvailable</RunLevel>
</Principal>
  </Principals>
  <Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</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>true</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>true</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
<Exec>
  <Command>C:\Windows\System32\cmd.exe</Command>
  <Arguments>/q /c "C:\Users\---------\Documents\PowerBI\PowerShell\RunExcelRefreshingScriptPowerShell2.bat"</Arguments>
</Exec>
  </Actions>
</Task>

您可以在没有用户名或密码的情况下提供任务计划设置的导出。

我有很多通过任务计划程序运行的功能,而不是一个问题,因为我的调度程序调用了启动powershell的bat。

TaskSchedulerLastRunResult

这是您可以找到最后一次运行结果的地方。

我遇到了同样的问题,我创建了一个计划任务来运行我创建的PowerShell脚本。 我发现如果你在程序/脚本窗口中添加Powershell.exe的路径(即:%SystemRoot%\\ system32 \\ WindowsPowerShell \\ v1.0 \\ powershell.exe)以及实际PowerShell脚本的路径(即:D) :\\ Scripts \\ PowershellScript.ps1)(参见下面的示例)它将在Arguments窗口中工作。 您还必须检查服务器的PowerShell执行策略,以确保它设置为“不受限制”。 您也可以尝试将其添加为参数(-ExecutionPolicy Bypass)。 我希望这会对某人有所帮助。 示例: 运行PowerShell脚本的任务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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