简体   繁体   English

使用PowerShell使用“运行是否用户已登录”选项来安排任务创建

[英]Schedule task creation with option “”Run whether user is logged in or not“” using powershell

I have below schedule task powershell script which creates a schedule task and runs under a service account. 我在下面的计划任务powershell脚本中创建了计划任务并在服务帐户下运行。

$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. 仅供参考:我无法在此脚本中提供密码。

Thanks 谢谢


Update 更新资料

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. 然后,您当然不必在脚本中对密码进行硬编码,而是使用安全字符串从文本文件中读取密码。

暂无
暂无

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

相关问题 如何Powershell任务管理器的脚本“无论用户是否登录都运行” - How to Powershell a script for Task Manager to "run whether a user is logged on or not" 在“运行是否登录用户”模式下,使用任务计划程序运行Powershell脚本会冻结 - Running Powershell script using Task Scheduler freezes when in “Run whether user is logged in or not” mode 如何在 PowerShell 中无论用户是否登录都安排任务? - How to schedule a task wether the user is logged on or not in PowerShell? 设置“无论用户是否登录都运行”时,PowerShell 不会作为计划任务运行 - PowerShell doesn't run as scheduled task when “Run whether user is logged on or not” is set 无法使用具有选项“仅在用户登录时运行”的 powershell 创建计划任务 - Cannot create Scheduled task with powershell that has option “run only when user is logged on” 任务调度程序“无论用户是否登录都运行”问题到启动应用程序 - Task scheduler "Run whether user is logged on or not" issue to startup application Powershell:将计划任务设置为在用户未登录时运行 - Powershell: Set a Scheduled Task to run when user isn't logged in 以登录用户身份运行Powershell脚本 - Run powershell script as logged in user 无法设置“运行用户是否登录” - Unable to set “Run whether user is logged on or not” PowerShellPack - TaskScheduler模块 - 运行没有记录用户的任务 - PowerShellPack - TaskScheduler module - run task with no logged user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM