简体   繁体   English

计划任务 PowerShell 或 CMD 脚本 - “以管理员身份运行”

[英]Scheduled Task PowerShell or CMD script - “Run As Administrator”

I've created a PowerShell script which lists the scheduled tasks and the LastRunResult .我创建了一个 PowerShell 脚本,其中列出了计划任务和LastRunResult I'm using Get-ScheduledTask command.我正在使用Get-ScheduledTask命令。 I need to put it at the end of every scheduled task to send a notification related to the LastRunResult .我需要将它放在每个计划任务的末尾,以发送与LastRunResult相关的通知。

The problem is that Get-ScheduledTask command doesn't work properly and do not show ALL scheduled tasks but just some of them.问题是Get-ScheduledTask命令不能正常工作,并且不显示所有计划任务,而只显示其中一些。 To be able to see all scheduled tasks the Get-ScheduledTask command needs to be run from the CMD or PowerShell console with administrative privileges.为了能够查看所有计划任务,需要从 CMD 或 PowerShell 控制台以管理权限运行Get-ScheduledTask命令。 And it works from there.它从那里开始工作。 But it doesn't work when I run such script from Task Scheduler.但是当我从任务计划程序运行这样的脚本时它不起作用。 Checking Run with highest privileges doesn't work. Run with highest privileges不起作用。 Specifying Policy -Bypass doesn't work as well.指定Policy -Bypass也不起作用。

Does anyone know how to execute Get-ScheduledTask from Task Scheduler ran in administrator mode to list all scheduled tasks?有谁知道如何从以管理员模式运行的任务计划程序执行Get-ScheduledTask以列出所有计划任务?

This can be caused if you have UAC enabled or are logged on as a user who is not an administrator.如果您启用了 UAC 或以非管理员用户身份登录,则可能会导致此问题。 Ensure the runas account is a local administrator.确保 runas 帐户是本地管理员。

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

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