Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check the PowerShell version.
PowerShell
Write-Output $PSVersion[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .Minor instead of .Major
Trying to print $PSVersion without a property
✗ Incorrect
The .Major property shows the main version number of PowerShell.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing .Minor or .Build instead of .Major
Using -eq instead of -ge for comparison
✗ Incorrect
Checking the major version number lets you know if it's PowerShell 7 or newer.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like ToInt() or ToNumber()
Trying to access properties instead of calling a method
✗ Incorrect
The .ToString() method converts the version object to a readable string.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping .Major and .Minor
Using .Build or .Revision instead of .Minor
✗ Incorrect
The major version is 5 and the minor version is 1 for PowerShell 5.1.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .Revision instead of .Build
Mixing up the order of properties
✗ Incorrect
Use .Major, .Minor, and .Build properties to get the respective version numbers.