繁体   English   中英

另一个任务计划程序未执行PowerShell

[英]Another Task Scheduler not executing PowerShell

我有一个简单的PowerShell脚本,它只能创建一个文件。 针对更大的PowerShell脚本进行测试。

在Windows Server 2012 R2上运行-64位

它以管理员帐户运行。

运行用户是否已登录

以最高特权运行


行动:程序/脚本:Powershell.exe(我已经尝试过这种方法和完整路径)

添加参数:-NoProfile -executionpolicy remotesigned-文件C:\\ Scripts \\ test.ps1


Get-executionPolicy:RemoteSigned

已将“管理员”添加到:Set-PSSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI

“管理员”具有“以批处理身份登录”权限“管理员”在Admins组中

用于测试的PowerShell脚本:

    $text = "Hello World"

    $text | Set-Content TestMyFile.txt
    $text | Out-File TestMyFile.txt
    $text > TestMyFile.txt

    # This is to write into a file or append to the text file created:
    $text | Add-Content TestMyFile.txt
    $text | Out-File TestMyFile.txt -Append
    $text >> TestMyFile.txt

没什么,只是尝试确保Task Scheduler将执行PowerShell脚本。

那我想念什么?

在输出代码中使用完整路径,并且对于将来在Task Scheduler中运行脚本遇到的任何问题,应首先获取日志记录和try/catch块,以查看脚本正在生成什么错误/输出,然后再寻求进一步的帮助。 这样做将帮助您更快地找到答案并同时更快地学习。

提示:始终仅在Task Scheduler的“要运行的程序”方面为程序命名,因为Task Scheduler使用其自己的包装器来执行操作,并且在极少数情况下,如果将整个执行行放在其中,它可能会产生不良结果。这个领域。 始终将参数放在参数字段中。

暂无
暂无

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

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