Adding ‘Edit with PowerShell ISE’ and ‘Open PowerShell here (as Admin)’ to the context menu

In order to edit PowerShell files within PowerShell ISE I used to just drag and drop them from Windows Explorer into the ISE scripting pane. Unfortunately this doesn’t work anymore (I believe since Windows 8). The best explanation for the behaviour I found is here. In short drag and drop doesn’t work from Windows Explorer to an elevated application because of the higher Mandatory Integrity Control (MIC) level of the drag & drop source (Windows Explorer has a default level of medium while the elevated application runs with a high MIC level). There are several workarounds available but they all have negative side effects (elevating explorer to a higher privileges, disabling UAT…).
The workaround I’m using is adding a context menu for all PowerShell related files to Edit them with PowerShell ISE (while there is already a default ‘Edit’ context menu entry for PowerShell ISE I like to have it open a specific platform version elevated without loading profile). In addition to that I also like to add a context menu entry to open up a PowerShell command prompt from any folder or drive in Windows Explorer:
I wrapped the creation of the context menu into a function. The function offers to following options:

  • Add ‘Edit with PowerShell ISE’ context menu entry
  • Add ‘Open PowerShell here’ context menu entry (to Directories, Directory Backgrounds and Drive(s))
  • The type of context menu entry can be specified by using the contextType parameter
  • Specify the platform (x64 is default) of Windows PowerShell to open
  • Add the -noProfile switch when opening ISE or PowerShell console (-noProfile switch)
  • Run the PowerShell instance as admin (-asAdmin switch)

Example usage:

Add-PowerShellContextMenu -contextType editWithPowerShellISE -platform x86 -asAdmin
Add-PowerShellContextMenu -contextType openPowerShellHere -platform x86 -asAdmin

Below is the source code for ‘Add-PowerShellContextMenu’, but the function can also be downloaded via GitHub.


Photo Credit: slack12 via Compfight cc


I'd love to hear what you think

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s