zoukankan      html  css  js  c++  java
  • Windows Task Scheduler Run Powershell Script(Windows计划任务执行powershell脚本)

    最近遇到一个需求:把powershell脚本添加到Windows计划任务中每天执行。

    刚开始看起来比较简单,但是当直接把ps1文件添加到Task Scheduler时,不能正常运行

    首先在powershell中开启运行脚本的权限为无限制的环境:

    然后在计划任务中执行任务进行测试,结果没能实现powershell中的功能。查看执行日志,发现运行脚本的实例居然是:

    Task Scheduler launch task "\PowerShell\powershell" , instance "C:\Windows\System32\notepad.exe"  with process ID 71824.

    所以没有效果也正常。

    于是查阅了一些资料,有一种办法是直接让ps1文件能够双击运行,这个没有尝试。

    这里用了一个.bat脚本调用powershell脚本,从而实现计划任务执行powershell脚本。

    然后设置任务要执行的文件为text.bat

    然后执行任务,成功完成powershell中的程序。

    test.ps1源码:(调用test.ps1文件)

    powershell E:\test.ps1

    test.bat源码:(在E盘创建一个Atest的文件夹)

    New-Item E:\Atest -type directory
  • 相关阅读:
    JS基础算法题(一)
    JS数组的迭代器方法
    使用IcoMoon制作字体图标
    CSS浮动属性
    使用hibnate向数据库写入图片对象
    hibernate_基本配置和初始化步骤
    ORM框架
    Jsp中的session
    mysql的自我复制
    分页技术
  • 原文地址:https://www.cnblogs.com/tylertang/p/3075352.html
Copyright © 2011-2022 走看看