I am trying to run a PowerShell script using Task Scheduler and it pops up a PowerShell command console window.
Is there a way to disable this while running the script and hide the window?
I've tried -WindowStyle Hidden but the PowerShell command console window still pops up.
Since
powershell.exeis a console program, you can't execute it normally without its console window appearing (although you can hide it shortly after it starts by using-WindowStyle Hidden, as you have noted).The trick is to execute
powershell.exeitself in a hidden state. One way to do this is by using the WshShell object'sRunmethod to run a PowerShell command line as hidden from inside a WSH script, and execute the WSH script usingwscript.exe(which is not a console program, so no console window appears). Example script (JScript):If this script is
C:\Scripts\My Launcher.js, you can now run the following command line:This runs the launcher script without a console, which then runs the PowerShell command in a hidden window (the
Runmethod's second parameter is0).