0
0
PowerShellscripting~10 mins

First PowerShell command - Interactive Code Practice

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

Complete the code to display the text "Hello, World!" in PowerShell.

PowerShell
Write-[1] "Hello, World!"
Drag options to blanks, or click blank then click option'
AHost
BOutput
COutputLine
DHostLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using Write-Output instead of Write-Host for direct console display.
Misspelling the command name.
Using commands that do not exist in PowerShell.
2fill in blank
medium

Complete the code to store the number 5 in a variable named $num.

PowerShell
$num = [1]
Drag options to blanks, or click blank then click option'
A"5"
B5
C$5
Dfive
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes, which makes it a string.
Using invalid variable names like $5.
Writing the number as a word instead of a digit.
3fill in blank
hard

Fix the error in the code to correctly display the value of $name variable.

PowerShell
Write-Host [1]
Drag options to blanks, or click blank then click option'
A"name"
Bname
C$name
D'$name'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign before the variable name.
Putting the variable name inside quotes which prints the literal text.
Using single quotes which do not expand variables.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers 1 to 3.

PowerShell
for ($i = 1; $i [1] 3; $i[2]) { Write-Host $i }
Drag options to blanks, or click blank then click option'
A-le
B++
C-lt
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' instead of '-le' causing the loop to stop early.
Using '--' which decreases the counter instead of increasing.
Using incorrect operators causing syntax errors.
5fill in blank
hard

Fill all three blanks to create a hashtable with keys 'Name' and 'Age' and print the 'Name'.

PowerShell
$person = @{ [1] = 'John'; [2] = 30 }`nWrite-Host $person.[3]
Drag options to blanks, or click blank then click option'
AName
BAge
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around keys in the hashtable.
Accessing the hashtable with wrong key names.
Mixing up keys when printing the value.