I have a PS script initialized by Windows Task Scheduler that runs every five minutes. I've noticed when it initiates, the command prompt opens up briefly then goes away (the very nature of the script itself which is understandable). However, I want to hide it in the background because every five minutes the command prompt comes up and can be obstructive. I've tried to check the checkbox "hidden" in Windows Task Scheduler, but the result is the script will not run.
I have also tried writing -Hidden
in the arguments field of the Task Scheduler properties. The script will not run.
Is there a line of code that will enable my PS script to run in the background and not obstruct usage of the desktop environment?
I am not interested in wrapping it in .bat
or VB script. I am curious if there is a line of PS code I can add to universally work with any .ps1
. I am aware of a VB script solution provided below and if last resort, will have to use it:
https://www.sapien.com/blog/2006/12/20/schedule-hidden-powershell-tasks/
The short answer is no. You'll always get the PowerShell window at least flash momentarily (such as with -WindowStyle Hidden
) because of the way it's executed. The answer is, unfortunately, one of the solutions you're not interested in: wrap it in an executable or launch it with the VB script below.
Dim shell,command
command = "powershell.exe -nologo -command \\path-to\your-script.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0'