Hide window when running PowerShell scripts in Task Scheduler
Whenever you run a PowerShell script, a PowerShell window opens. You don't want windows to appear in cases where you want the script to run in Task Scheduler.
I will explain how to execute the PowerShell script with the window hidden.
JScript
You can hide the window by calling a PowerShell script from WSH(Windows Script Host).
filename: launch_ps.js
var shell = WScript.CreateObject("WScript.Shell"); var args = WScript.Arguments; var cmd = "" for(var i=0; i < args.length; i++) { cmd += " " + args(i) } var ret = shell.Run("powershell.exe -ExecutionPolicy RemoteSigned -File" + cmd, 0, true); WScript.Quit(ret);
Registration in task scheduler
This section describes registration to the task scheduler under the following conditions.
launch_ps.js : Script above
test.ps1 : PowerShell script you want to launch
Place these two in c:\temp
Item | Set value |
---|---|
Program/script | wscript |
Add arguments | launch_ps.js test.ps1 |
Start in | c:\temp |
Please replace according to each environment.
Tweet
What can't be achieved without JScript is a bug called the PowerShell specification.
Link
See below for how to call a PowerShell script from VBA such as EXCEL without hiding the window.