Challenge - 5 Problems
PowerShell File Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Copy-Item command?
You run this PowerShell command:
Assuming the file exists and the destination folder exists, what does the command output?
Copy-Item -Path 'C:\Test\file.txt' -Destination 'C:\Backup\' -PassThru
Assuming the file exists and the destination folder exists, what does the command output?
PowerShell
Copy-Item -Path 'C:\Test\file.txt' -Destination 'C:\Backup\' -PassThru
Attempts:
2 left
💡 Hint
The -PassThru parameter makes Copy-Item output the copied item object.
✗ Incorrect
The -PassThru parameter tells Copy-Item to output the copied item as a FileInfo object, showing its full path. Without it, Copy-Item outputs nothing.
💻 Command Output
intermediate2:00remaining
What happens when you run this Move-Item command?
Consider this command:
What is the result if 'data.csv' exists in both source and destination folders?
Move-Item -Path 'C:\Temp\data.csv' -Destination 'C:\Archive\data.csv'
What is the result if 'data.csv' exists in both source and destination folders?
PowerShell
Move-Item -Path 'C:\Temp\data.csv' -Destination 'C:\Archive\data.csv'
Attempts:
2 left
💡 Hint
By default, Move-Item does not overwrite existing files.
✗ Incorrect
Move-Item throws an error if the destination file exists unless you use -Force to overwrite it.
📝 Syntax
advanced2:00remaining
Which option correctly copies all .txt files recursively?
You want to copy all .txt files from 'C:\Docs' and all its subfolders to 'D:\Backup'. Which command is correct?
Attempts:
2 left
💡 Hint
Use -Include with -Recurse to filter files recursively.
✗ Incorrect
Only option A correctly uses -Include with -Recurse to copy all .txt files recursively. Options B and C misuse -Filter or path, D ignores subfolders.
🔧 Debug
advanced2:00remaining
Why does this Move-Item command fail?
You run:
But it fails with an error: "Move-Item : Cannot find path 'C:\Source\*' because it does not exist." What is the problem?
Move-Item -Path 'C:\Source\*' -Destination 'C:\Dest'
But it fails with an error: "Move-Item : Cannot find path 'C:\Source\*' because it does not exist." What is the problem?
PowerShell
Move-Item -Path 'C:\Source\*' -Destination 'C:\Dest'
Attempts:
2 left
💡 Hint
Check if the source folder has any files matching the wildcard.
✗ Incorrect
If the source folder is empty, the wildcard * matches no files, causing Move-Item to error that the path does not exist.
🚀 Application
expert3:00remaining
How to atomically move and rename multiple files with PowerShell?
You want to move all .log files from 'C:\Logs' to 'D:\Archive' and rename them by adding a timestamp prefix, e.g., '20240601_file.log'. Which script snippet achieves this correctly and safely?
Attempts:
2 left
💡 Hint
Use Get-ChildItem with ForEach-Object to rename and move each file in one step.
✗ Incorrect
Option A correctly gets each .log file, then moves it with a new name including the timestamp prefix. Option A is invalid syntax, A tries to rename before moving but pipes incorrectly, D renames then moves but renaming changes the file path causing Move-Item to fail.