简体   繁体   English

PowerShell 计划任务:打开 PowerShell 和要运行的脚本但不执行脚本

[英]PowerShell scheduled task: opens PowerShell and script to be run but doesn't execute script

$Trigger = New-ScheduledTaskTrigger -AtLogOn
$User = "Administrator"
$Action = New-ScheduledTask -Execute "PowerShell_ISE.exe" -Argument "C:\Payload\XML_Read.ps1"
Register-ScheduledTask -TaskName "StartupScript_PS" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest -Force

This is my code which creates a scheduled task and runs fine upon logon.这是我的代码,它创建一个计划任务并在登录时运行良好。 the problem is when it logs on it opens PowerShell and the XML_Read file but I have to manually click run for the XML file to be read etc. Is there a way I can modify my code to do this for me?问题是当它登录时它会打开 PowerShell 和 XML_Read 文件,但我必须手动单击运行才能读取 XML 文件等。有没有办法可以修改我的代码来为我执行此操作? thanks in anticipation.期待中的感谢。

You can't execute scripts automatically with the ISE.您无法使用 ISE 自动执行脚本。 Instead of PowerShell_ISE.exe, use PowerShell.exe.使用 PowerShell.exe 代替 PowerShell_ISE.exe。

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

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