PowerShell is a powerful tool for automating tasks and managing systems, but with multiple versions available, it can be tricky to manage them effectively. This guide covers everything you need to know about checking your PowerShell version, installing the latest version alongside older ones, setting your preferred version as the default, and running commands using specific versions.


1. Checking Your Installed PowerShell Version

The first step in managing PowerShell versions is to check which version is currently installed.

A. Checking the Current Version


$PSVersionTable.PSVersion

Explanation: This command outputs the currently installed PowerShell version.

Alternative Method:


Get-Host | Select-Object Version

How to Try It: Open a PowerShell window and run these commands to confirm your version.


2. Installing the Latest PowerShell Version

PowerShell Core (6.x and 7.x) is the modern, cross-platform version of PowerShell, which can coexist with the older Windows PowerShell (versions 1.0 to 5.1). Installing PowerShell Core does not overwrite the existing Windows PowerShell.

A. Downloading PowerShell Core

Go to the official PowerShell Releases Page and download the installer for your operating system (.msi for Windows).

B. Installing PowerShell Core

Run the downloaded installer and follow the prompts. By default, it will be installed in:


C:\Program Files\PowerShell\7\

How to Verify Installation:

$PSVersionTable.PSVersion

3. Does PowerShell 7 Automatically Become the Default?

No, installing PowerShell 7 does not automatically make it the default version. It installs alongside Windows PowerShell, so typing powershell in the command prompt will still launch the older version, while typing pwsh will launch PowerShell 7.


4. Setting PowerShell 7 as the Default

A. Modifying the System Path

  1. Open System Properties (press Win + R, type sysdm.cpl, and hit Enter).
  2. Go to the Advanced tab and click Environment Variables.
  3. Edit the Path variable and add:
    
    C:\Program Files\PowerShell\7\
    

How to Confirm: Open a new command prompt and type:

$PSVersionTable.PSVersion

5. Running Commands Using Different PowerShell Versions

A. Using Windows PowerShell


C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\path\to\script.ps1"

B. Using PowerShell Core


C:\Program Files\PowerShell\7\pwsh.exe -File "C:\path\to\script.ps1"

Inline Command:


"C:\Program Files\PowerShell\7\pwsh.exe" -Command "Get-Process"

6. Using PowerShell Versions in Scheduled Tasks

  1. Open Task Scheduler and click Create Task.
  2. Under the Actions tab, click New.
  3. In the Program/script field, enter:
    
    C:\Program Files\PowerShell\7\pwsh.exe
    
  4. In the Add arguments field, enter:
    
    -File "C:\path\to\your\script.ps1"
    

7. Potential Risks and Considerations When Upgrading

  • Compatibility Issues: Existing scripts written for older versions may not work in PowerShell 7.
  • Third-Party Dependencies: Some software might rely on older versions of PowerShell.
  • Environmental Changes: Adjusting system paths can impact automated tasks.
  • Older Systems: Windows 7 or older servers may require additional updates before installing PowerShell Core.

8. Disclaimer

Upgrading or changing your PowerShell environment can impact existing scripts and software. Always test changes in a non-production environment before making them on critical systems. Back up your scripts and system settings to avoid disruptions. This guide is provided for informational purposes only, and the author is not responsible for any issues resulting from its use.