jamieb919
jamieb919

Reputation: 1

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? thanks in anticipation.

Upvotes: 0

Views: 103

Answers (1)

Mike Shepard
Mike Shepard

Reputation: 18176

You can't execute scripts automatically with the ISE. Instead of PowerShell_ISE.exe, use PowerShell.exe.

Upvotes: 4

Related Questions