简体   繁体   English

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

[英]Another Task Scheduler not executing PowerShell

I have a simple PowerShell script that just creates a file. 我有一个简单的PowerShell脚本,它只能创建一个文件。 Testing this for a bigger PowerShell script. 针对更大的PowerShell脚本进行测试。

Running on Windows Server 2012 R2 - 64-bit 在Windows Server 2012 R2上运行-64位

its running under the Administrator account. 它以管理员帐户运行。

Run whether user is logged on or not 运行用户是否已登录

Run with highest privileges 以最高特权运行


Action: Program/Script : Powershell.exe (I've tried it this way and the full path) 行动:程序/脚本:Powershell.exe(我已经尝试过这种方法和完整路径)

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


Get-executionPolicy: RemoteSigned Get-executionPolicy:RemoteSigned

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

"Administrator" has "Log on as batch job" permissions "Administrator" is in the Admins group “管理员”具有“以批处理身份登录”权限“管理员”在Admins组中

PowerShell Script for testing: 用于测试的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

Nothing fancy, just trying to make sure Task Scheduler will execute a PowerShell script. 没什么,只是尝试确保Task Scheduler将执行PowerShell脚本。

So What am I missing? 那我想念什么?

Use full paths in your output code, and for any future problems with running scripts from Task Scheduler, you should first put in logging and try/catch blocks to see what errors/outputs the script is generating before seeking further assistance. 在输出代码中使用完整路径,并且对于将来在Task Scheduler中运行脚本遇到的任何问题,应首先获取日志记录和try/catch块,以查看脚本正在生成什么错误/输出,然后再寻求进一步的帮助。 Doing this will help you find the answer faster & learn faster at the same time. 这样做将帮助您更快地找到答案并同时更快地学习。

Tip: Always only name the program in the 'Program to run' aspect of Task Scheduler, as the Task Scheduler uses its own wrapper to execute the action, and in rare occasions, it can produce undesired results if you place the entire execution line in this field. 提示:始终仅在Task Scheduler的“要运行的程序”方面为程序命名,因为Task Scheduler使用其自己的包装器来执行操作,并且在极少数情况下,如果将整个执行行放在其中,它可能会产生不良结果。这个领域。 Always put parameters in the parameters field. 始终将参数放在参数字段中。

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

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