PowerShell is an advanced form of command prompt. It is extended with a huge set of ready-to-use cmdlets and comes with the ability to use .NET framework/C# in various scenarios. When you double-click on a *.ps1 script file, it opens in Notepad or other app associated with this file type. Sometimes it can be very useful to create a shortcut to run your PS1 script file directly.
By default, Windows comes with a context menu command 'Run with PowerShell', which is available for PS1 files. However, if your script has no user input and doesn't include a pause at the end, the PowerShell output will disappear quickly. Another issue is the default execution policy which may prevent your script from being started from the context menu. By following the instructions below, you will be able to create a shortcut for your PS1 file and simply run it by double-clicking on the shortcut. This is very convenient and time saving.
In this article, I will use the following PS1 file as an example:
To create a shortcut for a PS1 PowerShell file in Windows 10, do the following.
- Copy the full path to your PS1 script file.
- Right click the empty space on your Desktop. Select New - Shortcut from the context menu (see the screenshot).
- In the shortcut target box, type the following:
powershell.exe -noexit -ExecutionPolicy Bypass -File
- Now, paste the path to your script file. You will get something like this:
powershell.exe -noexit -ExecutionPolicy Bypass -File c:\data\winaero\winaero.ps1
- Give your shortcut some meaningful name. You can use any name you want. Click on the Finish button when done.
You are done. Double-click on the shortcut to run your script.
Now, you can move this shortcut to any convenient location, pin it to taskbar or to Start, add to All apps or add to Quick Launch (see how to enable Quick Launch). You can also assign a global hotkey to your shortcut.
Articles of interest:
- Generate QR Code with PowerShell in Windows 10
- Find Your Windows Upgrade History with PowerShell
- Create Windows 10 Bootable USB Stick With PowerShell
- Get amount of words, chars and lines in a file using PowerShell
- Add PowerShell As Administrator Context Menu in Windows 10
- Add PowerShell file (*.ps1) to New Context Menu of File Explorer
- Get File Hash With PowerShell in Windows 10
- How To Restart Computer with PowerShell
- Start a Process Elevated from PowerShell