Automate "Files on Demand" cleanup?


Hey Everyone,

Wondering if there is a way to write a batch file that I can manually run to mimic the Right Click, Free Up Space for OneDrive files on demand?

I have several hundred GB of files on SharePoint that takes up a lot of space on my local drive once I have accessed them.

Any thoughts?

Comments (4)

4 responses to “Automate "Files on Demand" cleanup?”

  1. Paul Thurrott

    Sounds like an IFTTT type solution would work. Or, since you're using Office 365, Power Automate.

  2. timo47

    I think you can do this with the old Disk Cleanup tool (cleanmgr.exe) which has an option for deleting all local OneDrive files except the ones you marked to always have an offline version.

    For automating this, lookup the Microsoft support article "Automating Disk Cleanup Tool in Windows".

  3. prifici

    Storage Sense might do this? "Settings/System/Storage Sense/Configure Storage Sense or run it now" has options to mark OneDrive/SharePoint files as online-only after X amount of days.

    • evox81

      In reply to prifici:

      This is my recommendation. Set it to remove online files after a desired time, click the "clean now" button and then it'll run periodically thereafter.