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.

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? Commented Dec 9, 2021 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. Commented Dec 9, 2021 at 20:15
  • stackoverflow.com/a/51007810/4181058 Commented Dec 9, 2021 at 20:40
  • Just tried that, I think it works now. Thank you. Commented Dec 9, 2021 at 20:41
  • Does this answer your question? PowerShell in Task Manager Shows Window Commented Jun 22, 2023 at 18:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.