When you right-click a PowerShell script in File Explorer, you typically find a context menu entry called “Run with PowerShell” which lets you easily execute the PowerShell script.
However, on some systems, the “Run with PowerShell” command is missing. It turns out the command is hidden once you define a non-default “OpenWith” command. To repair this, all you need to do is delete this registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice
Deleting this key manually in regedit.exe is trivial, and once the key is removed, the “Run with PowerShell” context menu is visible again.
It turns out deleting the registry key with PowerShell is not trivial, though. All of these commands fail with the same exception, complaining that some subkey cannot be deleted:
PS C:\> Remove-Item HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice PS C:\> Remove-Item Registry::HKEY:CURRENT_USER:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice PS C:\> Remove-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice' PS C:\> Remove-Item HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\'.ps1'\UserChoice PS C:\> Remove-Item HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice -Recurse -Force
We’ll provide you with a solution to this challenge in an upcoming tip.
psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!