How to Prevent PowerShell Window from Showing Up with My Task Scheduler Script?

0
69
Asked By CuriousCat123 On

I've been using an older script that checks the uptime on a machine, and if it's been on for over seven days, it starts a countdown and reminds users every hour to reboot. This has worked well for me, but after upgrading to Windows 11, I've noticed that the countdown part of the script is now causing a PowerShell window to appear. This didn't happen when I was on Windows 10. I'm not very experienced with scripting, so I'm trying to figure out why this window pops up now. Does anyone know what could be causing this change? Here's a bit of my script for reference and the relevant parts where the counter is initialized.

4 Answers

Answered By TechGuru99 On

I think the issue might stem from how the script is structured. You see that line saying "Counter is at $counter"? The pound sign in front of it is supposed to make it a comment, so it shouldn’t run. But if there's a formatting error, that line could be appearing in your PowerShell window. Try removing that line completely and see if it still shows up.

Answered By DevDude88 On

It looks like Windows 11 manages PowerShell job windows differently than before. Now, they seem to pop up every time they output something. A quick fix is to run your script using `powershell.exe -WindowStyle Hidden` or wrap your job in `Start-Process` with the `-WindowStyle Hidden` flag. Just curious, what's triggering the popup? Is it from Task Scheduler or a startup script?

CuriousCat123 -

We use a proactive remediation script to check uptime, which triggers the scheduled task.

Answered By ScriptingSage42 On

Could you clarify how you're launching the script in Task Scheduler? In the Actions tab, there's an entry for "Start a program"—what do you have set as the program path and arguments? That might give us insight into how it’s executing.

CuriousCat123 -

It's set up as a scheduled task that activates when the machine has been on for more than seven days.

Answered By FindItFast On

Good news! I found the solution. Windows 11 handles scheduled tasks differently. I discovered a little VB script that can launch the PowerShell script while keeping that window hidden, which should solve your issue.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.