Pete Hinchley: Run a PowerShell Script from a Shortcut Without Displaying a Window

You've written a PowerShell script and you want to run it using a shortcut on the desktop. But when you do, a console window is briefly displayed. How do you hide it?

It's not enough to invoke PowerShell.exe using -windowstyle hidden, as a console window is displayed before PowerShell can process the parameter. The trick is to invoke PowerShell using the Windows Scripting Host (wscript.exe).

Let's start by creating a file named C:\Windows\System32\Hidden.vbs with the following content:

CreateObject("WScript.Shell").Run "" & WScript.Arguments(0) & "", 0, False

Assuming your PowerShell script is named C:\Windows\System32\Task.ps1, create a shortcut with the following Target:

C:\Windows\System32\wscript.exe C:\Windows\System32\Hidden.vbs "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -file C:\Windows\System32\Task.ps1"

Now when you double click the shortcut, the PowerShell script will be invoked without displaying a console window.