Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to display a message about script reliability.
PowerShell
Write-Output [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the message inside quotes causes errors.
Using echo without quotes outputs unexpected results.
✗ Incorrect
The Write-Output command requires a string in quotes to display the message correctly.
2fill in blank
mediumComplete the code to check if a file exists before reading it.
PowerShell
if (Test-Path [1]) { Get-Content [1] } else { Write-Output "File not found." }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the file path causes errors.
Using single quotes with backslashes can cause escape issues.
✗ Incorrect
File paths must be strings in quotes in PowerShell to be recognized correctly.
3fill in blank
hardFix the error in the script that tries to create a directory if it doesn't exist.
PowerShell
if (-Not (Test-Path [1])) { New-Item -ItemType Directory -Path [1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted paths causes command failures.
Using single quotes with backslashes can cause unexpected behavior.
✗ Incorrect
The path must be a string in quotes for Test-Path and New-Item to work correctly.
4fill in blank
hardFill both blanks to create a function that logs messages with timestamps.
PowerShell
function Log-Message {
param([string]$message)
$timestamp = Get-Date -Format [1]
Write-Output "$timestamp - [2]"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the date format string causes errors.
Using 'message' without $ does not insert the variable value.
✗ Incorrect
The date format string must be quoted, and the variable $message is used inside the output string.
5fill in blank
hardFill all three blanks to filter services that are running and display their names.
PowerShell
$services = Get-Service | Where-Object { $_.Status -eq [1] }
$names = $services | Select-Object -ExpandProperty [2]
$names | ForEach-Object { Write-Output [3] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting 'Running' causes filter failure.
Selecting wrong property or not expanding it causes errors.
Using wrong variable in ForEach-Object outputs nothing.
✗ Incorrect
We filter services with Status 'Running', select the 'Name' property, and output each name using $_.