0

Windows neophyte here.

I have a script to move video files from my Downloads folder to my Plex server. The script works fine.

I scheduled it to run every 30 minutes using Schtasks. This works fine but shows a window every time it starts.

schtasks.exe /CREATE /SC DAILY /MO 1 /TN 'MoveMKV' /TR 'powershell.exe C:\Users\rammjet\myApps\movemkv.ps1 -WindowStyle Hidden' /ST 07:00 /RI 30 /DU 24:00

I found an answer on Stack Overflow saying to use Start-Process to start the script with the hidden window flag. However, when I try to schedule that with Schtasks, the script does not trigger.

I tried the following two commands:

schtasks.exe /CREATE /SC DAILY /MO 1 /TN 'MoveMKV' /TR 'start-process powershell.exe -arg C:\Users\rammjet\myApps\movemkv.ps1 -WindowStyle Hidden' /ST 07:00 /RI 30 /DU 24:00

schtasks.exe /CREATE /SC DAILY /MO 1 /TN 'MoveMKV' /TR 'start-process -FilePath Powershell.exe -Args C:\Users\rammjet\myApps\movemkv.ps1 -WindowStyle Hidden' /ST 07:00 /RI 30 /DU 24:00

How can I periodically run the script without a window?

rammjet
  • 15
  • 3
  • as far as i can tell, the only way to COMPLETELY suppress the console window is to use wscript or vbs to call PoSh. lookee ... How to run a PowerShell script without displaying a window? - Stack Overflow — https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window – Lee_Dailey Nov 18 '20 at 18:30
  • @Lee_Dailey Thank you. I saw that post. It has 3 answers. The first one didn't look to be successful. The 2nd I ignored. The 3rd is where I started trying to use "start-process". I'm trying out the 2nd answer to see if that works. – rammjet Nov 18 '20 at 18:54
  • the 2nd one is the one that i have seen most often. that is what i would go with if you _really need_ to suppress the console window. – Lee_Dailey Nov 18 '20 at 19:33
  • After trying it, the "Copy-Item" in my script would fail. It works if I don't check that option. – rammjet Nov 18 '20 at 23:54
  • that sounds like a different problem. i would make a new Question on that subject - unless your search finds a fix 1st ... [*grin*] – Lee_Dailey Nov 19 '20 at 03:56
  • I only mention it because a comment on the reference thread was that the setting broke their script. It broke mine too. I have created a work-around, but it would be nice to know the right answer. – rammjet Nov 19 '20 at 16:16
  • kool! glad to know that you got it working ... [*grin*] – Lee_Dailey Nov 19 '20 at 17:22

1 Answers1

0

Thank you @Lee_Dailey for making me look again at a previous answer.

The 2nd answer in this post did the trick: How to run a PowerShell script without displaying a window?

I was having this same issue. I found out if you go to the Task in Task Scheduler that is running the powershell.exe script, you can click "Run whether user is logged on or not" and that will never show the powershell window when the task runs.

rammjet
  • 15
  • 3
  • 1
    Note that you can directly link to an individual answer by clicking `share` underneath it; in the case at hand: https://stackoverflow.com/a/50630717/45375 – mklement0 Nov 18 '20 at 23:27