Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

OneDrive Scripts

  • OneDriveMigrationScript.ps1 — copies files from OneDrive to another cloud folder
  • Dehydrate-Path.ps1 — frees local disk space by marking a path as cloud-only (details)

OneDrive Migration Script

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.

Features

  • 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

Requirements

  • Windows
  • PowerShell 5.1 or newer
  • OneDrive client installed and signed in
  • Destination cloud client installed and signed in (so files can upload)

Usage

  1. Save the script locally, e.g. OneDriveMigrationScript.ps1.
  2. Open PowerShell.
  3. Run the script:
# Example: run from the script folder
.\OneDriveMigrationScript.ps1
  1. 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)

What the script does

  • Lists all files under the OneDrive source (no folders)
  • Hydrates cloud-only files when needed
  • Copies into OneDriveMigration for 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

Excluded paths

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, so Archive does not exclude Archived
  • 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 $ExcludePaths at the top of the script; the setup still lets you add more

Skipped files

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)

Logging

  • Log file: OneDrive_Migration.log on the Desktop
  • Errors are collected and printed at the end

Notes and safety

  • 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.

Dehydrate-Path.ps1

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.

Usage

# 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.

What it does

  • 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 +U on 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

Notes

  • 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 -WhatIf to check the file list before running for real.

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages