On a Windows system, PowerShell 2.0 is included and installed by default. This old version is not necessary and can be uninstalled via the Control Panel. The steps below explain how you can start installing PowerShell 7.x.
Method 1: Install PowerShell 7.x via WinGet (Recommended)
- Open PowerShell as Administrator
- Use Win + X and select Windows Terminal (Admin).
- Install PowerShell using the following command:
winget install --id Microsoft.Powershell --source winget
This command downloads and installs the latest stable version of PowerShell. On new systems, WinGet may not have been installed. A good suggestion would be to first run the following command. It will tell you what to install first.
# Begin Function Confirm-Prerequisites
Function Confirm-Prerequisites {
$modules = @(
@{ Name = "Az" },
@{ Name = "Microsoft.Graph" }
)
if (-not $global:installed) {
foreach ($module in $modules) {
$installedModule = Get-InstalledModule -Name $module.Name -ErrorAction SilentlyContinue
if ($null -eq $installedModule) {
Write-Host "$($module.Name) is not installed. Installing the latest version..."
Install-Module -Name $module.Name -Force -Scope CurrentUser
} else {
$latestModule = Find-Module -Name $module.Name
if ($installedModule.Version -lt $latestModule.Version) {
Write-Host "$($module.Name) is installed but not the latest version. Updating to version $($latestModule.Version)..."
Update-Module -Name $module.Name -Force
} else {
Write-Host "$($module.Name) is installed and up-to-date. Version: $($installedModule.Version)"
}
}
}
# Check if Azure CLI is installed
if (Get-Command az -ErrorAction SilentlyContinue) {
Write-Host "Azure CLI is installed."
} else {
Write-Host "Azure CLI is not installed. Please install it from https://aka.ms/InstallAzureCli"
}
# Check if Winget is installed (only if not on Windows Server)
$osCaption = (Get-WmiObject -Class Win32_OperatingSystem).Caption
if ($osCaption -match "Windows Server") {
Write-Host "Skipping Winget check on Windows Server."
} else {
if (Get-Command winget -ErrorAction SilentlyContinue) {
$wingetVersion = winget --version 2>&1 | Out-String
if ($wingetVersion -match "v(\d+\.\d+\.\d+)") {
Write-Host "Winget is installed. Version: $($matches[1])"
} else {
Write-Host "Winget is installed but version could not be determined."
}
} else {
Write-Host "Winget is not installed. Please install it from https://aka.ms/GetWinget"
}
}
$global:installed = $true
Write-Host "Installation was successful. All prerequisites met. No further action needed."
} else {
Write-Host "All prerequisites met. No further action needed."
}
}
# End Function Confirm-Prerequisites
Confirm-Prerequisites
Method 2: Installing PowerShell 7.x via MSI Package
- Download the MSI Installer
Visit the PowerShell GitHub releases page and download the appropriate MSI package for your Windows 11 system. - Run the Installer
Open the downloaded MSI file and follow the installation instructions. - Verify the Installation
- After installation, open PowerShell and run:
$PSVersionTable
- After installation, open PowerShell and run:
This command will display the installed version of PowerShell. If you see this, PowerShell 7.x has been successfully installed.
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
If this is not the case, you can, for example, perform the following steps.
Set PowerShell 7.x as Default
Update Environment Variables
- Press Win + X and select System.
- Click on Advanced system settings.
- In the System Properties window, click Environment Variables.
- Under System Variables, locate the
Path
variable, select it, and click Edit. - Add the path to the PowerShell 7.x executable (e.g.,
C:\Program Files\PowerShell\7
) to the list.
Create a Shortcut
- Right-click on the desktop and select New > Shortcut.
- For the location, enter the path to
pwsh.exe
(e.g.,C:\Program Files\PowerShell\7\pwsh.exe
). - Name the shortcut “PowerShell 7” and click Finish.
Update PowerShell Profile
- Open PowerShell 7.x and run: powershellCopyEdit
if (!(Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force } notepad $PROFILE
- Add the following line to the profile script: powershellCopyEdit
$env:Path = "C:\Program Files\PowerShell\7;" + $env:Path
This ensures PowerShell 7.x is used in the environment path.
If You Prefer PowerShell ISE
Running the following in PowerShell ISE will show output like:
powershellCopyEditPS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.26100.2161
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.2161
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
This is because this version of PowerShell launches from:
shellCopyEdit%systemroot%\System32\WindowsPowerShell
For More Capabilities, Use Visual Studio Code (VS Code).
Benefits of VS Code with the PowerShell Extension
- Actively Maintained: VS Code and the PowerShell extension receive regular updates and new features.
- Cross-Platform: Works on Windows, macOS, and Linux.
- Advanced Features: Includes IntelliSense, debugging, integrated terminal, and Git support.
- Customizable: You can add extensions and themes to suit your workflow.
- Community Support: Large, active community with tutorials and shared extensions.
Switching to VS Code
- Install VS Code
- Download and install from the official website.
- Install PowerShell Extension
- Open VS Code
- Click the Extensions icon in the Activity Bar.
- Search for “PowerShell” and install the Microsoft extension.
- Configure PowerShell Version
- Open the Command Palette (
Ctrl+Shift+P
) - Search for and select PowerShell: Show Session Menu
- Choose the installed PowerShell version.
- Open the Command Palette (
Conclusion
If you prefer the simplicity and familiarity of PowerShell ISE, you can continue using it for basic tasks. However, for more advanced development and future-proof skills, switching to Visual Studio Code is recommended.
For more information about PowerShell, visit the Microsoft site. More about the author can be found on the Digitale Mels site.