Featured image of post Deconstructed: Convert OneDrive Files to Online-Only

Deconstructed: Convert OneDrive Files to Online-Only

Discover a useful little PowerShell script to effortlessly transform your OneDrive files into online-only mode, freeing up disk space by uploading files.

Managing OneDrive: Converting Files to Online-Only with PowerShell

28/06/2024 - 23.34 | Edit: Some of the information provided here is not fully comlpete. Further research has been done and an update is coming soon!

Hello there, another quick one to finish off the day. Let’s dive into a quick breakdown of a useful little PowerShell script we stumbled upon in Tristan Tyson’s tech blog whilst looking into Getting OneDrive File States with PowerShell. This small but handy script is all about converting your OneDrive (Commercial) files into online-only mode. This can be scoped for OneDrive (Personal) files as well.

This simple little script could be used to change the attribute of OneDrive files to ‘Cloud Only’, which would free up available disk space as any locally synced files are uploaded to OneDrive.

Let’s break it down step by step.

The Script: Streamlining Online-Only Conversion

The script focuses on using PowerShell to set your OneDrive (Commercial) files as online-only, saving local storage. You can check out the original post here, courtesy of Tristan Tyson.

Here’s the script laid out for you:

1
2
3
4
5
get-childitem $ENV:OneDriveCommercial -Force -File -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Attributes -match 'ReparsePoint' -or $_.Attributes -eq '525344' } |
ForEach-Object {
    attrib.exe $_.fullname +U -P /s
}

The Breakdown: What Each Part Does

  1. Gathering OneDrive Files: We start by using Get-ChildItem to get the OneDrive directory contents (recursively). The -File switch ensures we focus on files, and -Recurse dives into subdirectories.

  2. Choosing the Right Ones: With Where-Object, we pick files with specific attributes. Those with ‘ReparsePoint’ or ‘525344’ attributes are targeted as these attributes relate to locally availabile files (See my previous post: Getting OneDrive File States with PowerShell).

  3. Making the Change: For each chosen file, we employ attrib.exe to do the magic. The +U -P /s commands shift the file to online-only mode.

Embrace Streamlined OneDrive Management

And there you have it, folks! A straightforward dive into Tristan Tyson’s script for transforming OneDrive files into online-only mode. With a few lines of PowerShell, you can streamline your file management, making the most of online storage.

Feel free to use this script to optimize your OneDrive experience. Here’s to more efficient digital spaces and simplified file management!


With this script in your toolkit, you’ve got the power to make your OneDrive files online-only and keep things tidy. Stay tuned for more useful script breakdowns and tips!

Next time: We will look at creating a dashboard alert and automated remediation task for use with RMM software. This will likely utilise elements of or even combine this small script we haev created today and our previous script to Get OneDrive File Sync Status

Automate and script away - Happy Shellcode Saturday!

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy