Previously I wrote about how to create a Dynamic PowerShell Profile which allows you to choose upon execution of PowerShell whether you are running your scripts in a DEV state or PROD state.
In this article, I’ll go one step further and show you how to create a custom Desktop Shortcut that will automatically pass the parameters you’ve identified in your Dynamic PowerShell Profile so you don’t need to enter them when you double click the shortcut.
In this scenario, I want to have 2 desktop shortcuts. One that will open PowerShell using my DEV profile and one that will open my PROD profile. Technically, the shortcuts are opening the same PowerShell executable, and are running the same profile. The difference is in the parameter/s it is passing when it executes.
- Click Start and Enter “PowerShell” into the search bar (this is assuming you’re running Windows 7 or higher)
- Right Click the “Windows Powershell” result
- Choose Send To > Deskop (create shortcut)
- Right Click the new shortcut on your desktop
- Click Properties
- Click the Shortcut tab
- Place or cursor at the end of the text in the Target: field
- Enter the following text: -noprofile -noexit -command . $profile -inpType DEV
- The entire string will now look similar to: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noexit -command . $profile -inpType DEV
- Click OK
What Did We Just Do?
Let’s take a look at the additional text we added and break it down.
-noprofile = This tells powershell not to load the $profile we have created and associated with PowerShell. We’re not loading this initially because we want to easily pass a parameter without needing user interaction
-noexit = This tells PowerShell to stay open after executing. If you don’t include this, you’ll see the PowerShell application open and then it will disappear just like that. Allowing PowerShell to close right away is useful when you’re doing silent installs or other tasks that you don’t want/need the user to interact with the application once the process is complete.
-command . $profile = This tells PowerShell to run a command which is the . $profile command which is actually telling PowerShell to run the $profile script.
-inpType DEV = This tells PowerShell that you’re going to pass the $profile script a parameter with is named “inpType” which is created in the $profile script we created previously (you can name your parameters whatever you want). DEV is the parameter itself. You could pass PROD if you wanted instead.
Now, you can change the name of the shortcut to something like “DEV – Windows PowerShell” then copy and paste, rename the new one as “PROD – Windows PowerShell” then change the Target path entry to reflect a PROD parameter entry and now you have 2 shortcuts that will allow you to quickly run in DEV or PROD mode.
I hope this is useful to you. If you have questions or need assistance, feel free to post a question. If you need help adding to your profile, by all means post the question and hopefully I’ll be able to help you out.