DEV Community

Cover image for Move and Rename Files in PowerShell: Move-Item Explained
arnostorg
arnostorg

Posted on

Move and Rename Files in PowerShell: Move-Item Explained

Move and Rename Files in PowerShell: Move-Item Explained

Renaming and relocating files are common tasks. Learn the safe way to do both at once.

How It Works

Move-Item does two things: rename files and move them to different folders. In PowerShell, both operations are the same command—you just change the destination path or name.

When you move a file to the same folder with a different name, that's a rename. When you move it to a different folder, that's relocation.

Code Examples

Rename a File

# Rename file.txt to document.txt (stays in same folder)
Move-Item "file.txt" "document.txt"

# Shorter version using current path
Move-Item file.txt document.txt
Enter fullscreen mode Exit fullscreen mode

Move File to Another Folder

# Move file to archive folder
Move-Item "file.txt" "C:\archive\file.txt"

# Move AND rename in one step
Move-Item "file.txt" "C:\archive\document_old.txt"
Enter fullscreen mode Exit fullscreen mode

Move and Rename Together

# Move to new folder AND give it a new name
Move-Item "C:\current\report.xlsx" "C:\archive\report_2026.xlsx"
Enter fullscreen mode Exit fullscreen mode

Most Used Options

  • -Path - The file to move
  • -Destination - Where to move it to
  • -Force - Overwrite if destination already exists
  • -Confirm - Ask for confirmation before moving

The Trick: Power Usage

Always copy first for important files! Instead of moving directly:

# Risky - one-way operation
Move-Item "important.txt" "archive\important.txt"

# Safe - you have a backup
Copy-Item "important.txt" "archive\important.txt"
Get-ChildItem archive\important.txt  # Verify copy worked
Remove-Item "important.txt"  # Only delete after verifying copy exists
Enter fullscreen mode Exit fullscreen mode

This pattern protects you from losing files. Use it for anything valuable!

Learn It Through Practice

Stop reading and start practicing right now:

👉 Practice on your browser

The interactive environment lets you type these commands and see real results immediately.

Next in PowerShell for Beginners

This is part of the PowerShell for Beginners series:

  1. Getting Started - Your first commands
  2. Command Discovery - Find what exists
  3. Getting Help - Understand commands
  4. Working with Files - Copy, move, delete
  5. Filtering Data - Where-Object and Select-Object
  6. Pipelines - Chain commands together

Related Resources

Summary

You now understand:

  • How this command works
  • The most common ways to use it
  • One powerful trick to level up
  • Where to practice hands-on

Practice these examples until they feel natural. Then tackle the next command in the series.


Ready to practice? Head to the interactive environment and try these commands yourself. That's how it sticks!

What PowerShell commands confuse you? Drop it in the comments!

Top comments (0)