I wrote a powershell script to personalize the template paths for Office users and attached it to our Office GPO. It all worked well but every time the policy was pulled, the script window popped up and flashed for a second or so. Every user, every 90 minutes.
I tried "powershell.exe -WindowStyle Hidden", "| Out-Null", ">$nul 2&>1" and the tasks hidden flag but none worked.
Reason is that powershell.exe has a parameter -WindowStyle _with a possible value _Hidden
which obviously doesn't work as expected / is broken. The official issue: https://github.com/PowerShell/PowerShell/issues/3028
The workaround I found while reading the thread is:ps-run.vbs
Set objShell = CreateObject("Wscript.Shell")
Set args = Wscript.Arguments
For Each arg In args
objShell.Run("powershell -windowstyle hidden -executionpolicy bypass -noninteractive ""&"" ""'" & arg & "'"""),0
... and then call the powershell script you want to execute like this:
wscript "C:\Path\To\ps-run.vbs" "C:\Other\Path\To\your-script.ps1"
Now I can run my script out of the immediate scheduled task in my GPO without disturbing any user and config their session settings. Yay! Tested with Win10 x64 Build 1809, Win7 x86, Win7 x64.
Steps to reproduce In Windows Run dialog type this: PowerShell.exe -WindowStyle Hidden -Command ping www.microsoft.com Expected behavior There should be no window, right now you can't start pow...github.com