OneDriveMigrationScript.ps1— copies files from OneDrive to another cloud folderDehydrate-Path.ps1— frees local disk space by marking a path as cloud-only (details)
This PowerShell script copies files from OneDrive to a destination folder (default: Nextcloud). It hydrates cloud-only files when needed, verifies each copy by size, and writes a log to the Desktop. Only source files can be dehydrated, and only if you choose that option.
- Detects OneDrive accounts (Personal/Business) and lets you choose the source
- Finds common cloud destinations (e.g., Nextcloud, Dropbox, Google Drive) or uses a custom folder
- Excludes folders or files you don't want to migrate
- Hydrates files before copying (downloads cloud-only files)
- Copies via streaming and verifies file size
- Optional dehydrate of source files only
- Progress UI in the terminal and log file on the Desktop
- Resume support: skips files that already exist with the same size
- Windows
- PowerShell 5.1 or newer
- OneDrive client installed and signed in
- Destination cloud client installed and signed in (so files can upload)
- Save the script locally, e.g.
OneDriveMigrationScript.ps1. - Open PowerShell.
- Run the script:
# Example: run from the script folder
.\OneDriveMigrationScript.ps1- Follow the prompts:
- Confirm OneDrive account type
- Choose the source
- Enter exclude paths (optional, empty line to finish)
- Select the source dehydrate mode
- Choose or enter a destination folder (for "Custom" the exact folder is used)
- Lists all files under the OneDrive source (no folders)
- Hydrates cloud-only files when needed
- Copies into
OneDriveMigrationfor detected cloud destinations - If you choose "Custom", files are copied directly into the folder you enter (no extra subfolder is created)
- Verifies each file (size check)
- Optionally dehydrates source files, based on your selection
During setup you can list paths that should not be migrated. Excluded files are never touched: they are not hydrated, not copied, and not dehydrated (not even in "All" dehydrate mode).
Enter one path per line, empty line when done. Accepted forms:
| Input | Matches |
|---|---|
Archive |
the folder Archive and everything below it |
Notes\todo.txt |
that single file |
Pictures\RAW\* |
everything below Pictures\RAW |
*\temp\* |
any temp folder anywhere below the source |
C:\Users\me\OneDrive\Archive |
same as Archive (absolute paths inside the source are converted) |
Details:
- Entries without
*or?match a full path segment, soArchivedoes not excludeArchived - Matching is case-insensitive,
/and\both work - An entry without wildcards that does not exist in the source triggers a confirmation prompt
- Absolute paths outside the source folder are rejected
- To preset excludes, edit
$ExcludePathsat the top of the script; the setup still lets you add more
Files are skipped when:
- they already exist in the destination and the file size matches
- they are in the skip list (e.g.,
desktop.ini,Thumbs.db) - they match an exclude path (counted separately as "Excluded" in the summary)
- Log file:
OneDrive_Migration.logon the Desktop - Errors are collected and printed at the end
- Destination files are never dehydrated. The cloud client must upload them first.
- The script is conservative: copies are verified and faulty destination files are removed.
- Dehydration marks files as cloud-only. If not supported, files stay local.
- Test with a small folder first.
Frees local disk space for a path you no longer need offline. It clears the pin attribute on every locally stored file so OneDrive can drop the local copy. This is the dehydrate half of the migration script, standalone.
# Dry run first - shows what would happen, changes nothing
.\Dehydrate-Path.ps1 -Path 'C:\Users\me\OneDrive\Archive' -WhatIf
# Actually dehydrate
.\Dehydrate-Path.ps1 -Path 'C:\Users\me\OneDrive\Archive'
# Ask before every single file
.\Dehydrate-Path.ps1 -Path 'C:\Users\me\OneDrive\Archive' -Confirm-Path accepts a folder (processed recursively) or a single file. -WhatIf and -Confirm come from PowerShell's standard ShouldProcess support.
- Warns if the path is not below a known OneDrive folder (
$env:OneDrive,OneDriveConsumer,OneDriveCommercial) - Skips files that are already cloud-only
- Runs
attrib -P +Uon every remaining file - Shows progress while running, then a summary: dehydrated, already cloud-only, errors, space freed
- Files that fail are listed at the end; a single failure does not stop the run
- Dehydration is a request to the OneDrive client, not an instant operation. Files with an open handle or files OneDrive has not fully synced yet stay local and show up again on the next run.
- The reported "space freed" is the sum of the file sizes handed to OneDrive, not a measurement of actual disk usage.
- No excludes and no log file - use
-WhatIfto check the file list before running for real.