1 min read

Categories

1002140874_11967e2e51_m 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: editWithPowerShellISE openPowerShellHere 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: [code language=”powershell”] Add-PowerShellContextMenu -contextType editWithPowerShellISE -platform x86 -asAdmin Add-PowerShellContextMenu -contextType openPowerShellHere -platform x86 -asAdmin [/code] Below is the source code for ‘Add-PowerShellContextMenu’, but the function can also be downloaded via GitHub. https://gist.github.com/d598906c17f3fd2eabc9

shareThoughts


Photo Credit: slack12 via Compfight cc