Copy Files in PowerShell: Copy-Item with Safety
Duplicating files is one of the most common tasks. Learn to copy safely.
How It Works
Copy-Item creates a duplicate of a file or folder. The original stays, and you get a copy. You control where the copy goes and what to name it.
Always copy first before moving important filesβit's your safety net.
Code Examples
Copy Single File
# Copy file.txt to backup.txt (both in same folder)
Copy-Item file.txt backup.txt
# Result: You now have file.txt AND backup.txt
Copy to Different Folder
# Copy file to backup folder
Copy-Item report.txt C:\backup\report.txt
# Result: Original stays in current folder, copy is in backup folder
Copy Multiple Files
# Copy all .txt files to archive folder
Copy-Item *.txt C:\archive\
# All text files are copied, originals stay
Copy Entire Folder Structure
# Copy folder and everything inside it
Copy-Item C:\MyProject C:\MyProject_Backup -Recurse
# -Recurse copies subfolders and all their files
Most Used Options
- -Path - The file or folder to copy
- -Destination - Where to copy it to
- -Recurse - Copy folders and everything inside
- -Force - Overwrite if destination already exists
The Trick: Power Usage
The safe backup pattern:
# Before moving important files, copy them first
Copy-Item "important.xlsx" "backup\important.xlsx"
# Verify the copy worked
Get-ChildItem backup\important.xlsx
# Now the original is safe! You can move it knowing you have a backup
Copy with logging:
# See what gets copied
Copy-Item *.txt C:\archive\ -Verbose
# Shows each file as it copies
Learn It Through Practice
Stop reading and start practicing:
The interactive environment lets you type these commands and see real results.
Part of PowerShell for Beginners
This is part of the PowerShell for Beginners series:
- Getting Started - Your first commands
- Command Discovery - Find what exists
- Getting Help - Understand commands
- Working with Files - Copy, move, delete
- Filtering Data - Where-Object and Select-Object
- Pipelines - Chain commands together
Related Resources
Summary
You now understand:
- How this command works
- The most useful options
- One powerful trick
- Where to practice hands-on
Practice these examples until they're automatic. Mastery comes from repetition.
Practice now: Head to the interactive environment and try these commands yourself. That's how PowerShell clicks for you!
What would you like to master next?
Top comments (1)
Good safety checklist around Copy-Item. The next-level concern is the source/destination itself: once your SMB share is mounted as a drive letter, Copy-Item sees a normal filesystem path and the safety tips all apply the same way. ScsDriver handles SMB alongside S3 / SFTP / WebDAV, so the same mount client can target a Windows share today and a S3 bucket tomorrow β Copy-Item doesn't care, which is the point. Auto-reconnect across sleep / VPN / η½ε‘εζ’ means the user's drive letter survives their laptop state changes without the script author having to retry the copy themselves.
Couple of small notes from running Copy-Item across mount clients:
-Forcewill silently overwrite read-only files on most mount clients; that matches the 'safety' framing in this post, but it's worth being explicit.Get-Item -Stream *for NTFS alternate data streams doesn't work through any cloud-backed mount client β fall back to a local copy first if you really need ADSes.