Bird
Raised Fist0
PowerShellscripting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the PowerShell command Copy-Item do?
easy
A. Duplicates files or folders to a new location without removing the original
B. Deletes files or folders permanently
C. Moves files or folders to a new location and deletes the original
D. Renames files or folders in the current location

Solution

  1. Step 1: Understand the purpose of Copy-Item

    Copy-Item creates a copy of the specified file or folder at a new location, leaving the original intact.
  2. Step 2: Compare with other commands

    Unlike Move-Item, Copy-Item does not remove the original file or folder.
  3. Final Answer:

    Duplicates files or folders to a new location without removing the original -> Option A
  4. Quick Check:

    Copy-Item = Duplicate without deleting original [OK]
Hint: Copy-Item duplicates; Move-Item moves and deletes original [OK]
Common Mistakes:
  • Confusing Copy-Item with Move-Item
  • Thinking Copy-Item deletes the original file
  • Assuming Copy-Item renames files
2. Which of the following is the correct syntax to move a file named report.txt from C:\Docs to D:\Backup in PowerShell?
easy
A. Copy-Item -Source 'C:\Docs\report.txt' -Target 'D:\Backup'
B. Move-Item -Path 'C:\Docs\report.txt' -Destination 'D:\Backup'
C. Move-Item -Source 'C:\Docs\report.txt' -Target 'D:\Backup' -Force
D. Copy-Item -Path 'C:\Docs\report.txt' -Destination 'D:\Backup'

Solution

  1. Step 1: Identify the correct command for moving files

    Move-Item is used to move files; Copy-Item copies files.
  2. Step 2: Check the correct parameter names

    Move-Item uses -Path for source and -Destination for target location.
  3. Final Answer:

    Move-Item -Path 'C:\Docs\report.txt' -Destination 'D:\Backup' -> Option B
  4. Quick Check:

    Move-Item syntax = -Path and -Destination [OK]
Hint: Use Move-Item with -Path and -Destination to move files [OK]
Common Mistakes:
  • Using Copy-Item instead of Move-Item to move files
  • Using incorrect parameter names like -Source or -Target
  • Omitting quotes around paths with backslashes
3. What will be the result of running this PowerShell code?
Copy-Item -Path 'C:\Temp\file1.txt' -Destination 'C:\Backup' -Force
Move-Item -Path 'C:\Temp\file2.txt' -Destination 'C:\Backup'
medium
A. file1.txt is copied to C:\Backup; file2.txt is moved to C:\Backup and removed from C:\Temp
B. Both file1.txt and file2.txt are copied to C:\Backup; originals remain in C:\Temp
C. file1.txt is moved to C:\Backup; file2.txt is copied to C:\Backup
D. Both commands will fail due to missing parameters

Solution

  1. Step 1: Analyze Copy-Item command

    Copy-Item copies file1.txt to C:\Backup; -Force overwrites if exists; original remains.
  2. Step 2: Analyze Move-Item command

    Move-Item moves file2.txt to C:\Backup and deletes it from C:\Temp.
  3. Final Answer:

    file1.txt is copied to C:\Backup; file2.txt is moved to C:\Backup and removed from C:\Temp -> Option A
  4. Quick Check:

    Copy-Item copies; Move-Item moves and deletes original [OK]
Hint: Copy-Item keeps original; Move-Item removes original [OK]
Common Mistakes:
  • Assuming Move-Item copies instead of moves
  • Thinking Copy-Item deletes original file
  • Confusing -Force parameter effects
4. You run this command but get an error:
Move-Item -Path 'C:\Data\file.txt' -Destination 'C:\Archive\file.txt'

What is the most likely cause?
medium
A. The destination path includes the filename, causing a conflict
B. Move-Item cannot move files between drives
C. Move-Item requires the -Force parameter to work
D. The source file does not exist or path is incorrect

Solution

  1. Step 1: Check if source file exists

    Move-Item fails if the source file path is wrong or file missing.
  2. Step 2: Understand destination path usage

    Destination can include filename; this is valid and not an error cause.
  3. Final Answer:

    The source file does not exist or path is incorrect -> Option D
  4. Quick Check:

    Missing source file causes Move-Item error [OK]
Hint: Verify source file exists before moving [OK]
Common Mistakes:
  • Assuming destination filename causes error
  • Thinking Move-Item can't move across drives
  • Believing -Force is always required
5. You want to move all .log files from C:\Logs to D:\OldLogs, but keep a copy of the latest log file in C:\Logs. Which PowerShell commands achieve this?
hard
A. Copy-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs'; Move-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs' -Exclude 'latest.log'
B. Move-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs'; Move-Item -Path 'D:\OldLogs\latest.log' -Destination 'C:\Logs'
C. Move-Item -Path 'C:\Logs\latest.log' -Destination 'D:\OldLogs'; Move-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs' -Exclude 'latest.log'
D. Move-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs' -Exclude 'latest.log'; Copy-Item -Path 'C:\Logs\latest.log' -Destination 'C:\Logs'

Solution

  1. Step 1: Move latest.log first

    Move-Item moves latest.log to D:\OldLogs, removing it from C:\Logs.
  2. Step 2: Move all other .log files excluding latest.log

    Move-Item moves all other .log files to D:\OldLogs, excluding latest.log which is already moved.
  3. Final Answer:

    Move-Item -Path 'C:\Logs\latest.log' -Destination 'D:\OldLogs'; Move-Item -Path 'C:\Logs\*.log' -Destination 'D:\OldLogs' -Exclude 'latest.log' -> Option C
  4. Quick Check:

    Moving latest.log first then moving others excluding latest.log moves all logs correctly [OK]
Hint: Move latest.log first, then move others excluding latest.log [OK]
Common Mistakes:
  • Copying all files first losing latest.log
  • Moving latest.log to wrong folder
  • Using -Exclude incorrectly or in wrong command
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard