0

I dont want the blue window to pop up when my script gets run. It should be done in the background as it is for a screen at a public place :)

I tried with -Argument '-NoProfile -WindowStyle Hidden

My full code is:

function Create-Schedule{
    $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -command "& {C:\PowerPointScript\myscript.ps1}"'
    $trigger =  New-ScheduledTaskTrigger -Once -At (get-date) -RepetitionInterval (New-TimeSpan -Minutes 1)
    Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Powerpoint" -Description "Run Powerpoint download script every 5th min"
}
Jonas Borneland
  • 383
  • 1
  • 6
  • 19
  • 1
    You can use `-File` to launch a script. `-Argument '-NoProfile -WindowStyle Hidden -File "C:\PowerPointScript\myscript.ps1"'` – henrycarteruk Nov 26 '18 at 10:46
  • You could simple hide the console see more at - https://stackoverflow.com/a/40621143/6059896. Which would be a powershell only solution. – tukan Nov 26 '18 at 11:05
  • Possible duplicate of [How to run a PowerShell script without displaying a window?](https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window) – iRon Nov 26 '18 at 11:07

1 Answers1

0

The only solution to this problem seems to be to schedule this .VBS in the task scheduler.

 command = "powershell.exe -nologo -command C:\Scripts\YourScript.ps1"
 set shell = CreateObject("WScript.Shell")
 shell.Run command,0 
Bernard Moeskops
  • 1,203
  • 1
  • 12
  • 16
  • I´ll give it a try! – Jonas Borneland Nov 26 '18 at 10:27
  • Hmm dosn't seem to work. I edited the schedule added from my original script and pointet the file path to the .vbs script instead of the ps1 file... – Jonas Borneland Nov 26 '18 at 10:37
  • I've canged the path in your example to the right path like `C:\PowerPointScript\myscript.ps1` – Jonas Borneland Nov 26 '18 at 10:39
  • Sometimes schedules have really strange behavior, especially when editing and importing and exporting etc. Try to create a new fresh schedule and select the correct operating system and account etc. Also you could try to just double-click the .VBS to test if it is due to the script or due to the schedule. The script I provided should definitely work, I've tested on Windows 10 and Server 2012. – Bernard Moeskops Nov 26 '18 at 10:50
  • Nice one! Thanks for letting us know :) – Bernard Moeskops Nov 26 '18 at 11:17