0
0
PowerShellscripting~10 mins

Parameters in PowerShell - Interactive Code Practice

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

Complete the code to define a parameter named 'Name'.

PowerShell
param([string]$[1])
Write-Output "Hello, $Name!"
Drag options to blanks, or click blank then click option'
Aparam
BNameParam
CName
DInputName
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than the variable used in the script.
Forgetting to put the parameter inside the param() block.
2fill in blank
medium

Complete the code to make the parameter 'Age' mandatory.

PowerShell
param(
    [Parameter([1]=$true)]
    [int]$Age
)
Write-Output "Age is $Age"
Drag options to blanks, or click blank then click option'
AMandatory
BRequired
CForce
DNeeded
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Required' instead of 'Mandatory'.
Not using the Parameter attribute at all.
3fill in blank
hard

Fix the error in the parameter declaration to accept multiple strings.

PowerShell
param(
    [string[]]$[1]
)
Write-Output "Items: $($Items -join ', ')"
Drag options to blanks, or click blank then click option'
AList
BItem
CItemList
DItems
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the variable used in the script.
Forgetting the array type [string[]].
4fill in blank
hard

Fill both blanks to define a parameter 'Count' with a default value of 5.

PowerShell
param(
    [int]$[1] = [2]
)
Write-Output "Count is $Count"
Drag options to blanks, or click blank then click option'
ACount
B10
C5
DNumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the variable used.
Setting the wrong default value.
5fill in blank
hard

Fill all three blanks to create a parameter 'Verbose' that is a switch and mandatory.

PowerShell
param(
    [Parameter([1]=$true)]
    [[2]]$[3]
)
if ($Verbose) { Write-Output "Verbose mode on" }
Drag options to blanks, or click blank then click option'
AMandatory
BSwitch
CVerbose
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using Boolean instead of Switch for flags.
Not making the parameter mandatory when required.