1

I have set up a task on task scheduler to run a .bat file that runs a PowerShell script as admin which sets the DNS settings. I figured out how to make the .bat file run minimised, but the PowerShell window still pops up. Here is the script for the .bat file called "SetDNS". The PowerShell script's name is "DNS.ps1".

@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%DNS.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%C:\Users\Test\Downloads\DNS.ps1%""' -Verb RunAs}";

I want to change it so that the PowerShell script does not flash open while it runs. Is there something that I could add to the above code to make it run minimized? I tried to add "start /min" to the above code but it did not work.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Calmdiddy
  • 25
  • 5
  • 2
    You can try: PowerShell -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden....etc. But i think you still see the flash of a PowerShell prompt. Have you tried checking the 'Hidden' checkbox in your scheduled task instead? – Captain_Planet Dec 09 '21 at 19:05
  • Thanks for the comment, I tried that just now, and the script doesn't work. And yes, it is already hidden in the task scheduler. – Calmdiddy Dec 09 '21 at 20:15
  • https://stackoverflow.com/a/51007810/4181058 – Captain_Planet Dec 09 '21 at 20:40
  • Just tried that, I think it works now. Thank you. – Calmdiddy Dec 09 '21 at 20:41
  • Does this answer your question? [PowerShell in Task Manager Shows Window](https://stackoverflow.com/questions/50990966/powershell-in-task-manager-shows-window) – TylerH Jun 22 '23 at 18:40

0 Answers0