0
0
PowerShellscripting~20 mins

Copy-Item and Move-Item in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell File 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 Copy-Item command?
You run this PowerShell command:
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
AOutputs nothing (no output displayed)
BOutputs the copied file's full path as a FileInfo object
CThrows an error because -PassThru is invalid
DOutputs the content of the copied file
Attempts:
2 left
💡 Hint
The -PassThru parameter makes Copy-Item output the copied item object.
💻 Command Output
intermediate
2:00remaining
What happens when you run this Move-Item command?
Consider this command:
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'
AThe source file is copied but not deleted
BThe source file is moved and overwrites the destination file without prompt
CThe command throws an error about the destination file existing
DThe command renames the source file to avoid overwriting
Attempts:
2 left
💡 Hint
By default, Move-Item does not overwrite existing files.
📝 Syntax
advanced
2: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?
ACopy-Item -Path 'C:\Docs' -Destination 'D:\Backup' -Include '*.txt' -Recurse
BCopy-Item -Path 'C:\Docs' -Destination 'D:\Backup' -Filter '*.txt' -Recurse
CCopy-Item -Path 'C:\Docs\*.txt' -Destination 'D:\Backup' -Filter '*.txt' -Recurse
DCopy-Item -Path 'C:\Docs\*.txt' -Destination 'D:\Backup' -Recurse
Attempts:
2 left
💡 Hint
Use -Include with -Recurse to filter files recursively.
🔧 Debug
advanced
2:00remaining
Why does this Move-Item command fail?
You run:
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'
AThe wildcard * is not supported in -Path for Move-Item
BThe destination folder 'C:\Dest' does not exist
CThe command needs -Recurse to move all files
DThe source folder 'C:\Source' is empty, so * matches nothing
Attempts:
2 left
💡 Hint
Check if the source folder has any files matching the wildcard.
🚀 Application
expert
3: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?
AGet-ChildItem 'C:\Logs' -Filter '*.log' | ForEach-Object { Move-Item $_.FullName -Destination "D:\Archive\$(Get-Date -Format yyyyMMdd)_$($_.Name)" }
BGet-ChildItem 'C:\Logs' -Filter '*.log' | Rename-Item -NewName { "$(Get-Date -Format yyyyMMdd)_$_" } -PassThru | Move-Item -Destination 'D:\Archive'
CMove-Item 'C:\Logs\*.log' -Destination 'D:\Archive' -NewName "$(Get-Date -Format yyyyMMdd)_*.log"
DGet-ChildItem 'C:\Logs' -Filter '*.log' | ForEach-Object { Rename-Item $_ -NewName "$(Get-Date -Format yyyyMMdd)_$($_.Name)"; Move-Item $_.FullName -Destination 'D:\Archive' }
Attempts:
2 left
💡 Hint
Use Get-ChildItem with ForEach-Object to rename and move each file in one step.