How to hide command window at while running powershell script through the task scheduler?
Solution 1
As I undestand it's impossible without something like PSRun.exe file. I my situation I needed only message box on the user screen so I used windows msg.exe command to the localhost.
Solution 2
You can create another powershell script named for example "yourCallerPsScript" and call your first script like this:
$commpath = '"yourscriptpath\yourFirstPsScript.ps1"'
$strCommand = "powershell -WindowStyle hidden -file $($commpath)"
Invoke-Expression $strCommand
And in the task scheduler your run the new script:
Powershell -file "yourscriptpath\yourCallerPsScript.ps1"
Related videos on Youtube
Oleg Zagrebelsky
Updated on September 18, 2022Comments
-
Oleg Zagrebelsky over 1 year
I have powershell script with GUI form which show message by condition. This script is runnig through the task scheduler every 15 minutes. Every running shows me concole window, then GUI form with message and then console closed. This behavior irritate me. I'd like to hide console and display only GUI form. I tried runnig with argument "-WindowsStyle Hidden" but it didn't help.
How to hide this console window?
-
Matt Hanson about 8 yearsSee this question and answers on Stack Overflow: stackoverflow.com/q/1802127/5473
-
Oleg Zagrebelsky about 8 yearsIt doesn't help me. This answer works for script, not for script via task scheduler. As I understend I should use C# program PSRun.exe. Is there any solutions whithout .exe programs?
-
jscott about 8 yearsYou can come close with a scheduled task that runs the program
cmd.exe
with the arguments of/C START "" powershell -NoLogo -WindowStyle Hidden "C:\gui.ps1"
-- note that the console window will flash (incredibly briefly) and then close whilst thegui.ps1
executes.
-