0
0
PowerShellscripting~20 mins

Remove-Item in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Remove-Item Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Remove-Item command?
Consider a folder named 'TestFolder' containing files 'a.txt' and 'b.txt'. What happens after running this command?
Remove-Item -Path 'TestFolder\a.txt'
PowerShell
Remove-Item -Path 'TestFolder\a.txt'
AOnly 'a.txt' is deleted; 'b.txt' remains in 'TestFolder'.
BBoth 'a.txt' and 'b.txt' are deleted from 'TestFolder'.
CAn error occurs because the folder path is incomplete.
D'TestFolder' and all its contents are deleted.
Attempts:
2 left
💡 Hint
Remove-Item deletes the specified file or folder, not siblings unless specified.
💻 Command Output
intermediate
2:00remaining
What error does this Remove-Item command raise?
What error occurs when running this command if 'NonExistentFile.txt' does not exist?
Remove-Item -Path 'NonExistentFile.txt'
PowerShell
Remove-Item -Path 'NonExistentFile.txt'
AAccessDeniedException error.
BNo error; command silently succeeds.
CFileNotFoundException error.
DRemove-Item: Cannot find path 'NonExistentFile.txt' because it does not exist.
Attempts:
2 left
💡 Hint
By default, Remove-Item throws an error if the path is missing.
📝 Syntax
advanced
2:00remaining
Which Remove-Item command correctly deletes all files in a folder but keeps the folder?
You want to delete all files inside 'Logs' folder but keep the folder itself. Which command does this correctly?
ARemove-Item -Path 'Logs\*' -Force
BRemove-Item -Path 'Logs\*' -Recurse
CRemove-Item -Path 'Logs' -Recurse
DRemove-Item -Path 'Logs' -Force
Attempts:
2 left
💡 Hint
Use wildcard to target contents, not folder itself.
🚀 Application
advanced
2:00remaining
How to safely delete a folder and all its contents without prompt?
You want to delete 'OldData' folder and everything inside it without any confirmation prompts. Which command achieves this?
ARemove-Item -Path 'OldData' -Force
BRemove-Item -Path 'OldData' -Confirm:$false
CRemove-Item -Path 'OldData' -Recurse -Force
DRemove-Item -Path 'OldData' -Recurse
Attempts:
2 left
💡 Hint
Use parameters to suppress prompts and delete recursively.
🧠 Conceptual
expert
2:00remaining
What is the effect of running Remove-Item with -WhatIf parameter?
You run:
Remove-Item -Path 'Data\*' -Recurse -WhatIf

What happens?
AIt shows what would be deleted without actually deleting anything.
BIt causes a syntax error because -WhatIf cannot be combined with -Recurse.
CIt deletes files silently without any output.
DIt deletes the files and shows a confirmation prompt.
Attempts:
2 left
💡 Hint
-WhatIf is a safety feature to preview actions.