How to Uninstall Windows PowerShell

Hey, everyone! I captured your attention with that article title, didn’t I? If you’re the Windows geek I am, you probably thought, “Hey–I thought that Windows PowerShell was a core part of the operating system and can’t be removed. Besides, why would I WANT to remove PowerShell?”

Both are reasonable points. Before we get into the details, let me cut to the chase and give you my understanding of how PowerShell removal works:

  • PowerShell v2 is our baseline PowerShell version and cannot be uninstalled without damaging the integrity of Windows.
  • We can add or remove PowerShell v2 support from Windows 8.1 and Windows Server 2012 R2.
  • We can downgrade a manually upgraded PowerShell version by removing the corresponding Windows Management Framework (WMF) package.

As we both know, Windows XP is a a dead operating system. Therefore, I’ll just say for trivia and historical purposes that you can in fact completely remove Windows PowerShell v1 from XP.

Supposedly you could remove Windows PowerShell v2 from Windows Server 2008 RTM by going through Server Manager. However, there’s no Windows PowerShell runtime entry in the Add Features Wizard in Windows Server 2008 R2, as shown in Figure 1.

Figure 1: We can load or unload the ISE, but we can't remove Windows PowerShell v2 from Windows Server 2008 R2. (Image: Tim Warner)
Figure 1: We can load or unload the ISE, but we can’t remove Windows PowerShell v2 from Windows Server 2008 R2. (Image: Tim Warner)

I checked in Windows 7 SP1 and verified that we can’t uninstall Windows PowerShell v2 from the Windows Features dialog box in Control Panel.

If ever you’re wondering what version of the PowerShell runtime you’re currently working with, open a PowerShell console session and access the PSVersion property of the $PSVersionTable automatic variable like so:

$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1

Managing PowerShell v2 Coexistence

Because the Windows PowerShell team understands that many Windows systems administrators built scripts in PowerShell v2 that work just fine, thank you very much, they gave us the ability to enable or disable v2 support in Windows Server 2012 R2 and Windows 8.

In Windows Server 2012 R2, fire up an elevated console prompt and let’s see what’s available:

Get-WindowsFeature -Name *powershell*
Display Name Name
 ------------ ----
 [X] Windows PowerShell PowerShellRoot
 [X] Windows PowerShell 4.0 PowerShell
 [ ] Windows PowerShell 2.0 Engine PowerShell-V2
 [X] Windows PowerShell ISE PowerShell-ISE
 [ ] Windows PowerShell Web Access WindowsPowerShellWeb...

Thus, we can enable the Windows PowerShell v2 engine at any time:

Install-WindowsFeature -Name PowerShell-V2

To start a PowerShell v2, session, let’s back out of our current session and invoke the good ol’ cmd.exe shell:

cmd
 Microsoft Windows [Version 6.3.9600]
 (c) 2013 Microsoft Corporation. All rights reserved.

C:\>

Now we’ll start PowerShell v2 by using a special parameter and verify installation:

powershell -version 2.0
$PSVersionTable.Psversion
Major Minor Build Revision
 ----- ----- ----- --------
 2     0     -1    -1

Of course, we don’t have Get-WindowsFeature in Windows 8.1, so we’ll instead type the following at a Run or Cmd prompt to open the Windows Features dialog directly:

appwiz.cpl @,2

As shown in Figure 2, we can use the GUI to enable or disable Windows PowerShell v2. We use the same -version 2.0 parameter to invoke a v2 session.

Enable or disable the Windows PowerShell v2 engine in Windows 8.1. (Image: Tim Warner)
Enable or disable the Windows PowerShell v2 engine in Windows 8.1. (Image: Tim Warner)

Downgrading an Installed Windows PowerShell Version

Next, we’ll tackle the question of how we can roll back a newer PowerShell version that we installed on our server or client systems. We understand that each PowerShell version is tied to a particular .NET Framework version, and sometimes an innocent PowerShell version upgrade can break functionality.

Windows Server 2012 R2 and Windows 8.1 both have PowerShell v4 installed by default. Because v4 is the “latest and greatest” release version, we’ll turn our attention to Windows Server 2008 R2 and Windows 7.

On my Windows Server 2008 R2 test server, I went to the Microsoft Download Center and downloaded the Windows Management Framework 4.0 bits. Note that WMF packages use the Microsoft Update .msu file type, and that the packages are associated with a Microsoft Knowledge Base (KB) identifier. My WMF 4.0 package, for instance was named:

Windows6.1-KB2819745-x64-MultiPkg.msu

The .NET Framework Gotcha

Windows PowerShell v4 relies upon the .NET Framework 4.5. If you don’t have this .NET Framework version installed, the WMF installation completes without errors, but you won’t have Windows PowerShell v4, mark my words on that one.

Before you install WMF 4, download and install .NET Framework 4.5 and retry the WMF installation. You’ll need to reboot after installing WMF 4.0.

You should also know that a PowerShell version upgrade clobbers the previous version. This makes sense when you understand that newer PowerShell features may require a new copy of the ISE, replacement Windows Remote Management (WinRM) bits, and so forth.

The PowerShell version upgrade process works the very same way on Windows 7 SP1 systems.

Performing the Downgrade

Somewhat surprisingly, we can remove our WMF/PowerShell runtime from an elevated PowerShell console session! First, let’s locate the correct WMF install package by referencing its KB ID:

Get-HotFix -id KB2819745
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
WS2008R2 Update KB2819745 WS2008R2\Tim 3/20/2015

Now for the honkin’ long uninstallation string:

cmd.exe /c wusa.exe /uninstall /KB:2819745 /quiet /forcerestart

I’ll summarize each part of the preceding for you now:

  • /c: Instructs cmd.exe to carry out the following command and terminate
  • wusa.exe: Windows Update Standalone Installer
  • /KB: Note that we supply only the number here, not the KB prefix

Sure enough, my Windows Server 2008 R2 system is back to baseline:

$PSVersionTable.psversion
Major Minor Build Revision
----- ----- ----- -------
 2 0 -1 -1

Again, this downgrade process works identically in Windows 7 SP1.

PowerShell Uninstall Takeaways

So what have we learned? Number one, we recognize that especially going forward from Windows 7 and Windows Server 2008 R2, PowerShell is indeed a core OS component and will be ever-present in much the same way that the .NET Framework is.

We also learned how to selectively enable or disable PowerShell v2 support, which is sometimes useful for full backward compatibility with your scripts.

Finally, we now understand how to both upgrade and downgrade PowerShell versions by managing the WMF Windows Installer packages. I hope you found this article helpful–take care!