← Back to Tools Index

Archive Old Files

Version: 1.7.2 Last updated: March 28, 2026 Author: Doug Hesseltine

File servers do not get cleaner on their own. When policy says “anything older than N years belongs in cold storage,” you need a repeatable way to find, prove, and move data—without guesswork. Archive Old Files is one PowerShell script for Windows PowerShell 5.1 (no extra runtimes, no agents): aim it at a source tree and an archive root, set the age threshold, and get a preview-by-default plan before a single file moves. When you commit, it mirrors folder layout, avoids overwrites, summarizes how much space leaves the source, and can emit a polished HTML report plus a per-run log—so you, your team, and auditors can see exactly what ran. If you maintain shares or compliance windows, this is the kind of tool you keep in the kit.

Why use it?

Manual cleanup does not scale: you miss folders, misread dates, and you cannot show your work. This script gives you a consistent, documented workflow:

What it does

Recursive scan from -InputPath. Every file is compared to a cutoff (now minus -Years). Choose what timestamp drives age: last modified (default), last opened (NTFS last access time), the newer of modified or last access (so a recent open keeps the file), plus created or older of created vs modified when copies have refreshed “modified” dates.

Settings can be saved to JSON next to the script for the next run; a run log records parameters and each file that met the age rule.

Features at a glance

How it works

1
Scan

Recurse the source; probe permissions; list every file.

2
Filter

Keep files whose chosen timestamp is strictly older than the cutoff.

3
Map

Archive path = archive root + path relative to input root.

4
Report / act

Console summary; optional HTML. Add -Commit to move.

Safety rules

Archive must not live inside the source tree The script exits if the archive path equals or sits under the input path, so you never scan into the archive by mistake.
Preview is the default Nothing moves without -Commit. Try preview on a narrow path first if you are validating policy.

Existing files at the destination are never overwritten; a new numbered name is chosen instead.

How to run

Core parameters

Often used

Examples

Safe preview (nothing moves):

powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Archive-OldFiles.ps1 `
  -InputPath 'D:\Data' -ArchivePath '\\nas\archive' -Years 7

Commit, HTML report, no empty-folder prune prompt:

.\Archive-OldFiles.ps1 -InputPath 'D:\Data' -ArchivePath '\\nas\archive' -Years 7 `
  -Commit -Output HTML -RemoveEmptyFolders No

All shares, preview only (run on the file server):

.\Archive-OldFiles.ps1 -All -ArchivePath 'D:\ArchiveReports' -Years 7

Full parameter documentation:

Get-Help .\Archive-OldFiles.ps1 -Full

File servers & shares

When you do not pass all core paths on the command line, the script can list published disk shares on the machine so you can pick the source share or type a path. The archive defaults to the local path of the share named Archive (override with -ArchiveShareName). Use -SkipShareMenu for silent / scripted runs.

Reports & logging

HTML (optional): self-contained page with a compact header (server, domain, paths, counts, reclaim size) and a table grouped by full folder path. Columns include file name, owner, the date used for the age rule (header matches -AgeBasis), and size. Failed rows are highlighted; hover file names for full paths and errors. Folders with more than twenty files start collapsed; hover the folder block to expand.

Run log (Archive-OldFiles.run.log next to the config file, unless -NoRunLog): each run appends parameters plus a tab-separated list of every file that met the age rule. -All runs add SHARE_BEGIN / SHARE_END sections per share.

Config JSON (Archive-OldFiles.config.json): saves last-used settings; includes AllShares when you last used -All.

Download

Archive-OldFiles.ps1 (v1.7.2)

Save the script as Archive-OldFiles.ps1 (not .txt), then run from that folder.

Download Archive-OldFiles.ps1

Troubleshooting (Windows)

Source on GitHub

Repository (script + README): https://github.com/hesseltined/ServerCleanUpTools

← Back to Tools Index