3

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?

2
  • 1
    To run a command script and hide the window from appearing, call the task using VBScript.Run. Commented Apr 8, 2021 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. Commented Apr 8, 2021 at 23:57

2 Answers 2

0

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.

1
  • 1
    OP literally says he started with the "noninteractive" flag. Commented Dec 28, 2023 at 23:09
0

Thank you, JosefZ for solution!

Here is an example of VBS script.

' run_hidden.vbs Set objShell = CreateObject("WScript.Shell") objShell.Run "powershell.exe -ExecutionPolicy Bypass -File ""C:\path\to\script.ps1""", 0, False 

create script and add it to Start Program action.

  • program: wscript.exe
  • argument: "C:\path\to\run_hidden.vbs"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.