0
0
PowerShellscripting~15 mins

PowerShell versions (5.1 vs 7+) - Hands-On Comparison

Choose your learning style9 modes available
PowerShell versions (5.1 vs 7+)
📖 Scenario: You work in an IT team that manages many Windows computers. You need to check which PowerShell version is installed on each computer to decide if you can use new features from PowerShell 7 or if you must stick to PowerShell 5.1.
🎯 Goal: Build a simple PowerShell script that shows the installed PowerShell version and tells if it is version 5.1 or older, or version 7 or newer.
📋 What You'll Learn
Create a variable to hold the PowerShell version information.
Create a variable to hold the version threshold number 7.
Use an if statement to check if the installed version is 7 or higher.
Print a message showing the installed version and whether it is 5.1 or older, or 7 or newer.
💡 Why This Matters
🌍 Real World
IT professionals often need to know which PowerShell version is installed to use the right commands and scripts safely.
💼 Career
Knowing how to check and compare software versions is a basic skill for system administrators and automation engineers.
Progress0 / 4 steps
1
Get PowerShell version information
Create a variable called psVersion and set it to the value of $PSVersionTable.PSVersion.Major to get the major PowerShell version number.
PowerShell
Need a hint?

Use $PSVersionTable.PSVersion.Major to get the main version number of PowerShell.

2
Set version threshold
Create a variable called versionThreshold and set it to 7 to represent the minimum version for PowerShell 7 or newer.
PowerShell
Need a hint?

Just assign the number 7 to a variable named versionThreshold.

3
Check PowerShell version
Write an if statement that checks if $psVersion is greater than or equal to $versionThreshold. Inside the if, create a variable called message and set it to "PowerShell version $psVersion is 7 or newer.". In the else block, set message to "PowerShell version $psVersion is 5.1 or older.".
PowerShell
Need a hint?

Use -ge to compare numbers in PowerShell. Remember to use double quotes for strings with variables.

4
Display the result
Write a Write-Output command to print the message variable.
PowerShell
Need a hint?

Use Write-Output $message to show the message on screen.