使用选项“无论用户是否登录都运行"来安排任务创建使用 PowerShell [英] Schedule task creation with option ""Run whether user is logged in or not"" using powershell

查看:71
本文介绍了使用选项“无论用户是否登录都运行"来安排任务创建使用 PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下计划任务 powershell 脚本,它创建计划任务并在服务帐户下运行.

I have below schedule task powershell script which creates a schedule task and runs under a service account.

$taskname = ''myscheduletask'
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -command "& {stop-service -name "myservicename" -Force}"'
$trigger =  New-ScheduledTaskTrigger  -Once -At (Get-Date).AddSeconds($delayinSeconds)
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Description $taskdescription -Force

创建计划任务后,当前默认为仅在用户登录时运行",但我希望它为无论用户是否登录都运行".

After creating the schedule task, current default is 'Run only when user is logged on' however i want it to be "Run whether user is logged in or not" .

我在这里缺少什么设置?仅供参考:我无法在此脚本中提供密码.

What settings i am missing here ? Just FYI: i cannot supply the password in this script.

谢谢

最后我只使用了用户名和密码,它们将在脚本运行时被检索.

At last i ended up using user name and password only which will be retrieved during the script run time.

推荐答案

没有办法解决它 - 您必须提供凭据才能使其工作.当然,您不必在脚本中对密码进行硬编码,而是使用安全字符串从文本文件中读取.

There is not a way around it - you have to provide credentials for that to work. Then of course you don't have to hardcode the password in your script but instead read from a text file using secure strings.

这篇关于使用选项“无论用户是否登录都运行"来安排任务创建使用 PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆