0
0
PowerShellscripting~10 mins

PowerShell versions (5.1 vs 7+) - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check the PowerShell version.

PowerShell
Write-Output $PSVersion[1]
Drag options to blanks, or click blank then click option'
A.Minor
B.Major
C.Build
D.Revision
Attempts:
3 left
💡 Hint
Common Mistakes
Using .Minor instead of .Major
Trying to print $PSVersion without a property
2fill in blank
medium

Complete the code to detect if PowerShell version is 7 or higher.

PowerShell
if ($PSVersion[1] -ge 7) { Write-Output 'PowerShell 7 or newer' }
Drag options to blanks, or click blank then click option'
A.Major
B.Minor
C.Build
D.Revision
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing .Minor or .Build instead of .Major
Using -eq instead of -ge for comparison
3fill in blank
hard

Fix the error in the code to get the PowerShell version as a string.

PowerShell
$versionString = $PSVersionTable.PSVersion[1]
Drag options to blanks, or click blank then click option'
A.ToNumber()
B.ToInt()
C.ToString()
D.ToVersion()
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like ToInt() or ToNumber()
Trying to access properties instead of calling a method
4fill in blank
hard

Fill both blanks to create a condition that checks if PowerShell is version 5.1.

PowerShell
if ($PSVersionTable.PSVersion[1] -eq 5 -and $PSVersionTable.PSVersion[2] -eq 1) { Write-Output 'PowerShell 5.1 detected' }
Drag options to blanks, or click blank then click option'
A.Major
B.Minor
C.Build
D.Revision
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping .Major and .Minor
Using .Build or .Revision instead of .Minor
5fill in blank
hard

Fill all three blanks to create a dictionary with version parts as keys and their values.

PowerShell
$versionParts = @{ 'Major' = $PSVersionTable.PSVersion[1]; 'Minor' = $PSVersionTable.PSVersion[2]; 'Build' = $PSVersionTable.PSVersion[3] }
Drag options to blanks, or click blank then click option'
A.Major
B.Minor
C.Build
D.Revision
Attempts:
3 left
💡 Hint
Common Mistakes
Using .Revision instead of .Build
Mixing up the order of properties