Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TogglePS2

Temporarily enable and disable PowerShell 2.0 on modern Windows systems for legacy installer compatibility (for example, SQL Server 2014 Express setup), without leaving PowerShell 2.0 permanently enabled. This will hopefully get us over the compatibility issues introduced with deprecating a core dependency of some older installers that Microsoft (and others) provide.

Overview

This repository provides a guided, interactive workflow that:

  1. Validates prerequisites and required payload files.
  2. Builds a local C# helper executable at runtime (source provided).
  3. Enables PowerShell 2.0 components (GAC + registry) for legacy installers that have PowerShell 2.0 dependencies.
  4. Disables/removes those components after installation is complete.

The terminal window is designed to stay open while you install the legacy software, and then you can disable PowerShell 2.0 before closing the terminal window. Operations and their success or failure is reported in the terminal window.

If you close the terminal window before disabling PowerShell 2.0 per step 4, you can run the .bat again to disable it.

Usage:

  • Download repository files.
  • Run TogglePS2.bat as administrator.
  • Follow on-screen prompts to enable and disable PowerShell 2.0 features in Windows.
  • Recommended: Disable PowerShell 2.0 features once you've finished installing the legacy application for security.

Core helper:

  • TogglePS2.cs (compiled to %ProgramData%\TogglePS2\TogglePS2.exe at runtime, no manual build required)
  • TogglePS2.cs can be inspected with a text or code editor for auditing purposes before deployment.

Payload source:

  • ps2DLC/ (binary and resource DLL payload + legacy scripts)

Why This Exists

PowerShell 2.0 was removed from current Windows versions, but some older software installers still expect it. This project enables a controlled, temporary reintroduction and clean removal process to reduce long-term security exposure.

High-Level Program Flow

Run TogglePS2.bat as Administrator
    |
    +--> Require admin rights
    +--> Locate .NET 4.x C# compiler (csc.exe)
    +--> Validate ps2DLC payload files
    +--> Verify .NET Framework 3.5 is installed
    +--> Compile TogglePS2.cs -> %ProgramData%\TogglePS2\TogglePS2.exe
    |
    +--> Prompt: Enable PS2 now? [Y/n]
            |
            +--> If Yes: helper mode = enable
                    |
                    +--> Install DLLs into GAC (x86 + amd64 when applicable)
                    +--> Install localized resource DLLs for installed/current UI culture + en-US fallback
                    +--> Write PowerShell registry keys (32/64-bit views as needed)
                    +--> Repair ACLs if registry access is denied
                    +--> Verify PS2 registry state
            |
            +--> Prompt: Disable PS2 later? [Y/n]
                    |
                    +--> If Yes: helper mode = disable
                            |
                            +--> Delete PowerShell registry keys
                            +--> Remove DLLs from GAC
                            +--> Verify removal

What Gets Changed

GAC Operations

The helper installs/removes .dll payloads from:

  • ps2DLC/Binaries/x86
  • ps2DLC/Binaries/amd64 (64-bit OS)
  • ps2DLC/ResourceBinaries/<arch>/<culture> for:
    • installed UI culture
    • current UI culture
    • en-US

Registry Operations

Registry root managed by this project:

  • HKLM\SOFTWARE\Microsoft\PowerShell\1

Includes key paths such as:

  • ...\PowerShellEngine
  • ...\ShellIds\Microsoft.PowerShell
  • ...\ShellIds\ScriptedDiagnostics

On 64-bit systems, both native and WOW64 registry views are handled where appropriate.

Requirements

  • Windows (run with elevated Administrator privileges).
  • .NET Framework 4.x compiler available at one of:
    • %SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc.exe
    • %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\csc.exe
  • .NET Framework 3.5 installed and enabled.
  • Repository layout preserved (do not move payload folders unless you also update the scripts).

Quick Start

  1. Open an elevated Command Prompt or PowerShell window.
  2. Run TogglePS2.bat from the repository root.
  3. Press Y when prompted to enable PowerShell 2.0.
  4. Perform your legacy installer task (example: SQL Server 2014 Express install).
  5. Return to the prompt and press Y to disable PowerShell 2.0.

If you press N at the first enable prompt, the prompt will ask whether you want to run a disable remediation step immediately. This helps recover systems where PowerShell 2.0 may already be enabled from a prior interrupted session (or you accidentally close the terminal before disabling PowerShell 2.0).

Command Modes (Advanced)

The compiled helper supports these modes:

  • enable <ps2DLC folder>
  • disable <ps2DLC folder>
  • install <ps2DLC folder> (GAC only)
  • uninstall <ps2DLC folder> (GAC only)
  • writeRegistry <ps2DLC folder>
  • deleteRegistry <ps2DLC folder>

Example (after batch has compiled helper):

%ProgramData%\TogglePS2\TogglePS2.exe enable "C:\path\to\repo\ps2DLC"

Logs and Diagnostics

Runtime logs are written to:

  • %ProgramData%\TogglePS2\TogglePS2.log
  • %ProgramData%\TogglePS2\CompileHelper.log
  • %ProgramData%\TogglePS2\EnablePs2.log
  • %ProgramData%\TogglePS2\DisablePs2.log
  • %ProgramData%\TogglePS2\Verify.log

If the batch fails, check these logs first.

Troubleshooting

"This batch file must be run as Administrator"

Run from an elevated terminal.

".NET Framework 4.x C# compiler was not found"

Install/repair .NET Framework 4.x Developer/Targeting components so csc.exe is available.

".NET Framework 3.5 was not detected"

Enable .NET Framework 3.5 Windows feature before enabling PowerShell 2.0 compatibility.

Missing payload DLL errors

Ensure folder structure remains intact under ps2DLC/Binaries and ps2DLC/ResourceBinaries.

Registry access denied

The helper attempts ACL repair automatically, but elevation and local security policy may still block writes/deletes. Review the log files and run in a fully elevated session.

I pressed N at enable, now what?

If you skip enable (N), the script will offer a second prompt to run disable as remediation.

  • Press Y to force cleanup/removal of PowerShell 2.0 state.
  • Press N to exit without making changes.

Security Considerations

PowerShell 2.0 is legacy software and should not remain enabled longer than required.

Recommended practice:

  1. Enable immediately before the legacy installer step that requires it.
  2. Disable immediately after installation completes.
  3. Keep logs for change/audit tracking if used in managed environments.

Repository Contents

  • TogglePS2.bat: interactive orchestration script.
  • TogglePS2.cs: helper implementation for GAC + registry + verification.
  • ps2DLC/: payload binaries/resources and legacy PowerShell artifacts.
  • ps2DLC/loadGAC.ps1: older/manual approach retained for reference.
  • ps2DLC/regkeysNew/*.reg: registry templates (legacy/reference artifacts).

License and Attribution

  • This project is based on original Microsoft PowerShell code. (PS2DLC)
  • All contents of sub-folder ps2DLC are Microsoft original files supplied at: Microsoft
  • You can use those files from Microsoft or from the repo here as long as the file structure matches.

About

A script for temporarily enabling PowerShell 2.0 on modern Windows systems for compatibility with older installers.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages