0

I want to set up a task scheduler to run a PowerShell script every 1 hour with no prompt windows pop-up.

Here is the command I tried:

schtasks /create /sc hourly /tn $Task-Name /st $ScheduleTime `
/tr "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command C:\MyScript.ps1" `

I added all parameters I found.

-windowstyle hidden -NoLogo -NonInteractive -NoProfile

The script runs in the background with no problem but it still at the beginning pops up for a second before hides itself.

Does anyone know how to make a task scheduler to run the ps1 script fully hide with no pop-up windows?

Dave M
  • 4,494
  • 21
  • 30
  • 30
ITnewbie
  • 151
  • 1
  • 6
  • 1
    To run a command script and hide the window from appearing, call the task using [VBScript.Run](https://ss64.com/vb/run.html). – JosefZ Apr 08 '21 at 10:28
  • @JosefZ I refer to your link and solve the issue by the VBS. Thank you so much! Could you please post the answer below? Then I can accept the answer. – ITnewbie Apr 08 '21 at 23:57

1 Answers1

1

I am achieving this via the task scheduler, i have set the action value to start a powershell program with the following arguments:

-executionpolicy bypass -noninteractive -file "C:\PathToYourScript"

enter image description here

the key argument here is -noninteractive, it does not present an interactive prompt to the user.