2

The shortcut below executes powershell.exe and passes it the script vscode.ps1. It works except that for all my attempts, it still displays a terminal window briefly when running. You can see I've passed parameters which is supposed to prevent this, but I still see the window. What do I have to do to execute a PS script from a shortcut without the terminal window being displayed?

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -NoProfile -WindowStyle Hidden -file C:\Users\bernie\OneDrive\PowerShell\vscode.ps1 C:\Users\bernie\OneDrive\Documents\windows.txt

3 Answers 3

5

It's a known issue, see https://github.com/PowerShell/PowerShell/issues/3028#issuecomment-583834582

As @Ciantic mentioned, the best way to work around this issue is by using a VB script:

In, say ps-run.vbs put

Set objShell = CreateObject("Wscript.Shell")
Set args = Wscript.Arguments
For Each arg In args
    objShell.Run("powershell -windowstyle hidden -executionpolicy bypass -noninteractive ""&"" ""'" & arg & "'"""),0
Next

Then use it to run the command you want, e.g.

 wscript "C:\Path\To\ps-run.vbs" "C:\Other\Path\To\your-script.ps1"

I use something like this to run a task frequently without seeing any flashing windows.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. As a workaround I just configured the shortcut which runs the powershell command to run the window minimized. At least I don't see it unless I want to!
0

Yes, Powershell can't completely do this. But VBScript can do this. Also I use Hidden Start which can start any program hidden or bypass UAC.

Comments

0

Another option to run PowerShell scripts completely hidden (not even a flash) is to use this little RunHidden executable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.