Reverting PowerShell ISE’s focus problem - arcdev/engram404 GitHub Wiki
originally posted 2019-03-09 at https://engram404.net/reverting-powershell-ises-focus-problem/
Feel free to skip to the end How to fix your box
It seems that in the April 2018 (1803) Windows 10 update Microsoft decided to basically break PowerShell ISE so that whenever you do just about anything (like run a script, press F5, run a selection, press F8, create a new script tab) they've decided that the focus should go elsewhere. In the case of Run (F5 or F8) that means the focus goes from, let's say in the Script Pane where you're working, to the Console Pane where output would be. And, if you're a keyboard user (like me), you have no way to get back to the Script Pane with the keyboard (other than hide & show it or do some gymnastics).
There's even a great Feedback (User Voice) report here… that appears to have gone completely ignored.
I've had enough
I fired up a VM with the previous version of Windows 10. Started up PowerShell ISE, and, since this is .NET we're talking about, I ran a simple command to get all of the loaded assemblies (and their locations):
[System.AppDomain]::CurrentDomain.GetAssemblies() | Select-Object Location
(I'll not list them all here, but there's 70 or some of them.)
I figured somewhere within this set of assemblies was The Change that some hateful person introduced. At the last, I considered that it might be possible to pull all of these assemblies (and possibly their related resources and other dependencies) to a local folder to have an older, running, functional version of PowerShell ISE.
Next, I upgraded my VM to the dreaded 1803 (April 2018) release of Windows 10 and grabbed a snapshot of the VM (so I could put things back, if I really fouled them up).
I started by replacing all of the assemblies to find out if this was even going to work. Short version: it did.
The next thought was to try to narrow it down to the minimum number of changes necessary to '"fix'" PowerShell ISE.
In the end, only 2 files needed to be replaced with their older counterparts:
powershell_ise.exe
Microsoft.PowerShell.GPowerShell.dll
I actually suspect that Microsoft.PowerShell.GPowerShell.dll
is where the problem lies, but the newer version of powershell_ise.exe
didn't like the older version of GPowerShell
.
How to fix your box
- take ownership of these 2 files and grant Administrators permission to modify them.
You can run through a bunch of UI stuff or fire up a Command Prompt As Administrator and run these commands:
takeown /f "C:windowssystem32WindowsPowerShellv1.0powershell.exe" /a
takeown /f "C:WindowsMicrosoft.NETassemblyGAC_MSILMicrosoft.PowerShell.GPowerShellv4.0_3.0.0.0__31bf3856ad364e35Microsoft.PowerShell.GPowerShell.dll" /a
cacls "C:windowssystem32WindowsPowerShellv1.0powershell.exe" /e /p administrators:f
cacls "C:WindowsMicrosoft.NETassemblyGAC_MSILMicrosoft.PowerShell.GPowerShellv4.0_3.0.0.0__31bf3856ad364e35Microsoft.PowerShell.GPowerShell.dll" /e /p administrators:f
- replace the files with their older counterparts
if you trust me…
(No warranty either express or implied)
Go to my GitHub project -> revert-powershellise, clone it, and run revert.bat
from an Administrator Command Prompt.