Removing a folder across OneDrive for Business sites

Removing a folder across OneDrive for Business sites


This tool has been deprecated and replaced with the OneDrive for Business Admin Tool:

On a customer call a few weeks ago, I was asked if we could remove a specific folder across all (or a subset of) their OneDrive for Business sites.  There unfortunately isn’t a lot of information around accessing OD4B sites and folders programmatically, aside from our documentation on granting eDiscovery rights to a specific user (found here).

As you may (or may not) know, OneDrive for Business is really the “SharePoint MySites” construct, with the name changed to serve you better.  There have been additional features added in recent months (such as Delve), but conceptually, it’s still a site with permissions restricted to a single user.

Much like accessing an Exchange Online mailbox via the Exchange Online PowerShell, OD4B sites can have some level of management tasks performed from the SharePoint Online PowerShell.  With EXO, managing actual data objects inside the mailboxes can be performed via the Exchange Web Services API.  OD4B data objects can be accessed and managed with the SharePoint Client Components, which can be imported into a PowerShell session.

This script requires the SharePoint Online PowerShell module as well as the Client Components SDK.  The script will attempt to download them and install them automatically, or you can do it yourself by visiting:

– SharePoint Server 2013 Client Components SDK –

– SharePoint Online Management Shell

The syntax is pretty simple.  Run the script with the necessary parameters (Tenant, Username, Password, FolderToDelete) and the swich (GrantPermissions) see what you can see.  When you’re ready, add the -Confirm switch to remove the folders.

Removing a folder across OneDrive for Business sites

Follow the link below to download the script.  Many thanks to Vaibhav Upadhyay for his help with the SharePoint CSOM–couldn’t have done it without him! Happy removing!

Published by Aaron Guilmette

Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese.

Reader Comments

  1. Hi, great post!

    I have a reversed version of this problem. I have activated it for new users with:

    Set-SPOTenant –SharingCapability Disabled –ProvisionSharedWithEveryoneFolder $true

    I still want to create it for all the users that were created before we activated it again. Basically to get Delve work better with people using it. Is it possible for the Global Admin to run a script that does that?

    Best regards, Patrik

      1. Yeah i saw that, but its kind of time consuming to manually create all folders. Thank you for getting back to me so fast. I will keep looking for a script.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.