Freigeben über


Removing a folder across OneDrive for Business sites

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 - https://www.microsoft.com/en-us/download/details.aspx?id=35585

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

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!

https://gallery.technet.microsoft.com/Remove-a-OneDrive-for-c6fd3c30

Comments

  • Anonymous
    June 20, 2016
    Thanks for the blog. This is useful
  • Anonymous
    August 22, 2016
    Hi, great post!I have a reversed version of this problem. I have activated it for new users with:Set-SPOTenant –SharingCapability Disabled –ProvisionSharedWithEveryoneFolder $trueI 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