guide · static export
Productivity

Automate File Sorting With a Scheduled PowerShell Script

A Downloads folder that sorts itself by extension saves a minute every day. A scheduled script with a dry-run mode and a log does it without the risk of losing files.

by@guidox updated:10/31/26 time:30 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11 tools:PowerShell, Task Scheduler
TL;DR

Map **extensions to folders**, move files with a **scheduled PowerShell script**, and skip anything modified in the last **two minutes** so a download in progress is never moved. Log every move.

Before you start

Requirements

  • Windows PowerShell 5.1
  • A Downloads folder
  • Twenty minutes
Step by step

Instructions

01

Decide between a watcher and a schedule

A file system watcher reacts instantly but misses files that existed before it started, and it fires while a download is still being written. A scheduled run every ten minutes is duller and far more reliable.

02

Create the destination folders first

The script should only move files into folders that already exist, so a typo cannot create a dozen stray directories. Make one folder per type and keep the names short.

New-Item -ItemType Directory -Path D:\orted\ocs, D:\orted\mages, D:\orted\nstallers
03

Write the move loop with a dry run

Read the folder, filter by extension and print what would happen before anything moves. The -WhatIf switch is built into the move command and costs nothing to use.

Get-ChildItem $env:USERPROFILE\ownloads -File | Where-Object { $_.Extension -in '.pdf','.docx' } | Move-Item -Destination D:\orted\ocs -WhatIf
tipRun the real version once by hand before you schedule it. A script that works interactively and fails in a task is almost always a path problem.
04

Skip files that are still being written

A download writes into the target folder for seconds or minutes. Filter on the last write time so the run only touches files that have been quiet for a while.

$cutoff = (Get-Date).AddMinutes(-2)
... | Where-Object { $_.LastWriteTime -lt $cutoff }
⚠ warningWithout this filter a large ISO can be moved halfway through the download and the browser reports a failure.
05

Register the scheduled task

Create a task that runs as your account every ten minutes with the highest privileges off. Running as the logged-on user keeps the network drive mappings and the profile paths intact.

schtasks /create /tn "Sort Downloads" /tr "powershell -NoProfile -ExecutionPolicy Bypass -File C:\ools\ort-downloads.ps1" /sc minute /mo 10
06

Append every move to a log

One line per file with a timestamp turns a mysterious disappearance into a five second lookup. Write to a file next to the script, not to the console, which nobody sees in a scheduled run.

Add-Content C:\ools\ort.log "$(Get-Date -f s) $($_.Name) -> Docs"
Troubleshooting

Common issues

The task runs but no file moves

The working directory in a scheduled task is not your home folder. Use absolute paths everywhere or set the start-in folder in the task.

PowerShell refuses to run the script

Execution policy. Either pass -ExecutionPolicy Bypass in the task action or set it for the current user once.

Files disappear into the wrong folder

Check the log first, then the extension list. A catch-all default rule is what usually surprises people.

OneDrive keeps restoring the moved files

The folder is synced and the app protects it. Exclude Downloads from the sync or move the whole folder out of OneDrive.

FAQ

Frequently asked

Can this sort by date instead of extension?

Yes. Group on LastWriteTime and build the folder name from the month; the loop stays the same.

Does it work on Windows 10?

Yes. Both the script and the scheduled task behave the same on 10 and 11.

How to undo this

Run **Unregister-ScheduledTask -TaskName "Sort Downloads" -Confirm:$false** and the automation stops. Files already moved stay in the destination folders; move them back by hand or with one Get-ChildItem loop.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress