Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable WhatIf support for the Remove-Item cmdlet.
PowerShell
Remove-Item -Path 'C:\Temp\test.txt' [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -Confirm instead of -WhatIf shows a prompt instead of a simulation.
Using -Force or -Recurse does not simulate the action.
✗ Incorrect
The -WhatIf parameter shows what would happen if the command runs, without making changes.
2fill in blank
mediumComplete the code to prompt for confirmation before deleting a file.
PowerShell
Remove-Item -Path 'C:\Temp\data.log' [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -WhatIf only simulates the action without prompting.
Using -Force bypasses confirmation prompts.
✗ Incorrect
The -Confirm parameter asks for user confirmation before running the command.
3fill in blank
hardFix the error in the function to support WhatIf and Confirm parameters correctly.
PowerShell
function Remove-MyFile {
param(
[string]$Path
)
Remove-Item -Path $Path [1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only -WhatIf or -Confirm without values inside a function.
Using -Force disables confirmation and simulation.
✗ Incorrect
To support both WhatIf and Confirm, you must pass them as parameters with values.
4fill in blank
hardFill both blanks to add WhatIf and Confirm support to this advanced function.
PowerShell
function Remove-MyFolder {
param(
[string]$FolderPath,
[switch]$WhatIf,
[switch]$Confirm
)
Remove-Item -Path $FolderPath [1] [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding -WhatIf or -Confirm without using the parameters.
Forgetting to pass both parameters.
✗ Incorrect
Pass the switches as parameter values to enable WhatIf and Confirm support dynamically.
5fill in blank
hardFill all three blanks to create a function that supports WhatIf and Confirm and uses them in Remove-Item.
PowerShell
function Remove-ItemSafe {
param(
[string]$TargetPath,
[switch]$WhatIf,
[switch]$Confirm
)
Remove-Item [1] [2] [3]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing the path parameter correctly.
Mixing up the order of parameters.
Not using the switch values with :$ syntax.
✗ Incorrect
Pass the path and the switches $WhatIf and $Confirm to Remove-Item to support simulation and confirmation.