Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to validate that the parameter $Age is an integer.
PowerShell
param([[1]]$Age) Write-Output "Age is $Age"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [string] instead of [int] allows any text, not just numbers.
Using [bool] or [array] does not match the expected integer type.
✗ Incorrect
The [int] type validates that the parameter is an integer.
2fill in blank
mediumComplete the code to validate that the parameter $Name is mandatory.
PowerShell
param(
[Parameter([1]=$true)]
[string]$Name
)
Write-Output "Name is $Name" Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Optional instead of Mandatory allows skipping the parameter.
Using Position or ValueFromPipeline does not enforce requirement.
✗ Incorrect
The 'Mandatory' attribute makes the parameter required.
3fill in blank
hardFix the error in the code to validate that $Score is between 0 and 100.
PowerShell
param(
[ValidateRange([1], 100)]
[int]$Score
)
Write-Output "Score is $Score" Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as minimum excludes 0 which may be valid.
Using -1 allows negative scores which are invalid.
Using 100 as minimum is incorrect because max must be >= min.
✗ Incorrect
The ValidateRange attribute requires the minimum value first, which is 0.
4fill in blank
hardFill in the blank to validate that $Color is one of the allowed values.
PowerShell
param(
[ValidateSet([1])]
[string]$Color
)
Write-Output "Color is $Color" Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated sets like shapes or animals.
Not using quotes around the values.
✗ Incorrect
ValidateSet restricts the parameter to the specified values: Red, Green, Blue.
5fill in blank
hardFill all three blanks to validate $Count is an integer between 1 and 10 and mandatory.
PowerShell
param(
[Parameter([1]=$true)]
[ValidateRange([2], [3])]
[int]$Count
)
Write-Output "Count is $Count" Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting Mandatory to false or Optional allows skipping the parameter.
Using wrong range values like 0 or 11.
✗ Incorrect
The parameter is mandatory and must be between 1 and 10 inclusive.