How to move files with PowerShell by type or date
How to move files with PowerShell: by extension, by date and into dated folders, with a dry run first and name conflicts handled. Copy-and-paste scripts.
Written by the team building Quick File Organizer, folders that organize themselves, by your rules.
To move files with PowerShell you need two commands: Get-ChildItem to pick
the files and Move-Item to move them. Everything else — by type, by age, into
folders per month — is a filter between the two. The scripts below are ready to
paste, and each one starts in preview mode so nothing moves until you say so.
Move files with PowerShell: the basic pattern
Get-ChildItem "$env:USERPROFILE\Downloads" -Filter *.pdf -File |
Move-Item -Destination "D:\Documents\PDF" -WhatIf
-File skips folders. -Filter *.pdf selects by extension. -WhatIf prints
each move without doing it — delete that word when the output looks right. The
destination folder must already exist, or the first file is renamed to "PDF"
instead of being moved into it.
Move files by extension into matching folders
This sorts a whole folder: every file goes to a subfolder named after its extension, created when needed.
$source = "$env:USERPROFILE\Downloads"
Get-ChildItem $source -File | ForEach-Object {
$ext = $_.Extension.TrimStart('.').ToLower()
if (-not $ext) { $ext = "no-extension" }
$target = Join-Path $source $ext
New-Item $target -ItemType Directory -Force | Out-Null
Move-Item -LiteralPath $_.FullName -Destination $target -WhatIf
}
In practice, you will want groups rather than one folder per extension. A small lookup table does that:
$groups = @{
Documents = '.pdf', '.docx', '.xlsx', '.txt'
Images = '.png', '.jpg', '.jpeg', '.heic', '.gif'
Installers = '.exe', '.msi'
Archives = '.zip', '.7z', '.rar'
}
Loop over $groups.Keys, and for each one move the files whose extension is in
the list. Anything unmatched stays where it is.
Move files older than a number of days
Get-ChildItem "$env:USERPROFILE\Downloads" -File |
Where-Object LastWriteTime -lt (Get-Date).AddDays(-30) |
Move-Item -Destination "D:\Archive\Downloads" -WhatIf
LastWriteTime is the modified date. Use CreationTime if you mean "arrived
here more than 30 days ago" — a file extracted from an old archive is new to
the folder but has an old modified date.
Move files into year and month folders
$source = "$env:USERPROFILE\Pictures\Camera"
Get-ChildItem $source -File | ForEach-Object {
$target = Join-Path $source $_.LastWriteTime.ToString("yyyy\\MM")
New-Item $target -ItemType Directory -Force | Out-Null
Move-Item -LiteralPath $_.FullName -Destination $target -WhatIf
}
A file modified in November 2026 lands in Camera\2026\11. For photos, the
date the picture was taken is stored inside the file and can differ from the
file's own date; see
organizing photos by date.
Things that go wrong
| Problem | Why | Fix |
|---|---|---|
| "Cannot create a file when that file already exists" | A file with that name is already in the target | Rename on conflict, or -Force to overwrite |
A file with [1] in its name is skipped | Square brackets are wildcards in -Path | Use -LiteralPath |
| "The process cannot access the file" | The file is open or still downloading | Skip it and retry on the next run |
| "Running scripts is disabled on this system" | Default execution policy | Start with -ExecutionPolicy Bypass |
To keep both files on a name conflict, add a counter before moving:
$dest = Join-Path $target $_.Name
$n = 1
while (Test-Path -LiteralPath $dest) {
$dest = Join-Path $target ("{0} ({1}){2}" -f $_.BaseName, $n++, $_.Extension)
}
Move-Item -LiteralPath $_.FullName -Destination $dest
Run it automatically
To move files with PowerShell on a schedule, save the script as
C:\Scripts\sort-downloads.ps1. In Task Scheduler, create a
task that starts powershell.exe with these arguments:
-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\sort-downloads.ps1"
Set it to run daily, or at sign-in. A scheduled script runs on the clock, not when a file arrives; for that, you need a watcher — see how to monitor a folder for new files.
When a script is the wrong tool
When you move files with PowerShell, you also take on the upkeep: there is no
undo, no log unless you write one, and no preview once -WhatIf is gone. For a
one-off clean-up, that is fine. For something that touches your Downloads
folder every day, those are the parts that matter.
Quick File Organizer covers the same ground without code: rules by file type,
target folders with {Year}\{Month} in the path, a preview before anything
moves, and an activity log with Restore. Sorting on demand is free; real-time
monitoring is part of Pro.
Common questions
Does Move-Item work across drives?
Yes. Moving a file to another drive copies it and then deletes the original,
so it takes longer than a move within one drive. For whole folder trees across
drives, robocopy with /MOVE is the more dependable tool.
How do I move files from subfolders as well?
Add -Recurse to Get-ChildItem. Be careful if the destination is inside the
source folder — exclude it, or already-moved files get picked up again.
Can I undo it after I move files with PowerShell?
Not automatically. Write each source and destination to a log file as you go,
so a second script can reverse them — or use -WhatIf generously before real
runs.