【问题标题】:How to schedule a powershell script for automating wack process through windows scheduler?如何通过 Windows 调度程序安排用于自动化 wack 进程的 powershell 脚本?
【发布时间】:2013-04-22 22:22:19
【问题描述】:

我能够从 PowerShell 提示符和命令提示符处执行以下命令,但我无法使用 Windows 调度程序对其进行调度。

powershell脚本代码:

appcert.exe test -apptype metrostyle -packagefullname abc_somename -reportoutputpath C:\result.xml

appcert.exe 是 Microsoft 提供的 exe,用于在我的 Windows 8 应用程序上执行认证测试。我做了以下事情:

  1. 我正在使用代码制作文件ABC.ps1

    appcert.exe test -apptype metrostyle -packagefullname abc_somename -reportoutputpath C:\result.xml
    
  2. 我用这个代码创建了一个批处理文件PQR.bat

    powershell -command "& 'PathOfABC\ABC.ps1' "
    
  3. 我正在通过 Windows 调度程序进行调度。

在操作选项卡下创建任务时,我选择以下详细信息:

  • 操作:启动程序

  • 程序/脚本:批处理文件的路径

  • 开始于:包含批处理文件的文件夹路径

我安排它每 15 分钟运行一次。任务完成,但我在 C 盘中看不到任何 result.xml。你能指出我如何安排这个批处理文件每 15 分钟执行一次吗?

【问题讨论】:

    标签: powershell scripting batch-file scheduler


    【解决方案1】:

    使用 powershell -File "C:\path\to\ABC.ps1" 运行 powershell 脚本。或者将appcert.exe 命令直接放在批处理脚本中。运行批处理脚本来运行 PowerShell 脚本来运行可执行文件是没有意义的。

    假设您手动运行脚本时appcert.exe 创建C:\result.xml

    • 您是否已将执行策略设置为至少RemoteSigned
    • 运行任务的用户是否拥有Log on as batch job 权限?
    • 计划任务是否配置为以最高权限运行(假设已启用 UAC)?

    您是否尝试在脚本中添加一些调试代码,例如

    appcert.exe test ... >"%USERPROFILE%\appcert.log" 2>&1
    exit /b %errorlevel%
    

    appcert.log 在您尝试运行任务时是否被创建?它说什么?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 2018-06-10
      • 2014-10-22
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多