简体   繁体   English

任务计划程序 - Powershell 脚本未触发?

[英]Task Scheduler - Powershell script not firing?

I've created numerous scripts in Powershell that are working as intended if I execute them directly, however, when I try and setup a schedule to run these in Task Scheduler (to run with highest prilavages) it doesn't seem to be running anything at all.我在 Powershell 中创建了许多脚本,如果我直接执行它们,它们会按预期工作,但是,当我尝试设置一个计划以在任务计划程序中运行这些脚本(以最高权限运行)时,它似乎没有运行任何东西一点也不。

I'm running the following in my actions:我在我的行动中运行以下内容:

powershell.exe -ExecutionPolicy Bypass -File C:\PS\Mailboxes\CheckForwardingList.ps1

I'm getting a "Last Run Result" of 0x0 and the particular purpose of the above script is to generate a TXT file from EXO which it then mails out via SMTP and I've yet to receive any emails and I also don't see any TXT being generated in the folder where the script is located.我得到一个 0x0 的“上次运行结果”,上述脚本的特定目的是从 EXO 生成一个 TXT 文件,然后它通过 SMTP 邮寄出去,我还没有收到任何电子邮件,我也没有查看脚本所在文件夹中生成的任何 TXT。

I do have two additional scripts setup which aren't running but once I've addressed the issue on the above this should quickly rectify the problems.我确实有两个未运行的附加脚本设置,但是一旦我解决了上述问题,这应该会迅速纠正问题。

Extremely appreciative if people could point me in the right direction here?如果人们能在这里指出我正确的方向,非常感激? feels like I'm going in circles with something that from what I can tell should be working?感觉就像我在绕圈子,从我可以看出应该起作用的东西?

Many thanks非常感谢

I like to test my PowerShell scripts from a command prompt first.我喜欢先从命令提示符测试我的 PowerShell 脚本。

For example a script called C:\Tests\Test-PowerShellScriptsRunning.ps1 that only contains the following one liner helps me to test if scripts can run successfully on a machine例如,一个名为C:\Tests\Test-PowerShellScriptsRunning.ps1的脚本仅包含以下一个衬里,可帮助我测试脚本是否可以在机器上成功运行

Write-Host -ForegroundColor Yellow "If you see this, then your script is running"

Next, I run this script from a command prompt, to get the syntax right in my scheduled task:接下来,我从命令提示符运行此脚本,以在我的计划任务中获得正确的语法:

powershell.exe -nologo -file c:\Tests\Test-PowerShellScriptsRunning.ps1

Of course, you can add the -Executionpolicy bypass parameter, but I prefer to test the execution policy first.当然也可以加上-Executionpolicy bypass参数,不过我更喜欢先测试一下执行策略。

However, as you are running a script that connects to ExchangeOnline, I suspect it has to do with the user you are running this task under.但是,当您运行连接到 ExchangeOnline 的脚本时,我怀疑它与您正在运行此任务的用户有关。 Does the script run if you run this task under your credentials or are the credentials stored on the system or in the script?如果您在凭据下运行此任务,脚本是否会运行,或者凭据是否存储在系统或脚本中?

You might want to check this article to see how you can register an app and authenticate without storing your credentials on the machine to run the script unattended: App-only authentication for unattended scripts in the EXO V2 module您可能想查看本文以了解如何注册应用程序并进行身份验证,而无需将凭据存储在机器上以无人值守地运行脚本: EXO V2 模块中无人值守脚本的仅应用程序身份验证

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

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