Remove all users from onedrive via graph powershell

Rahamim Levi 156 Reputation points
2023-07-27T12:27:03.8933333+00:00

Hi everyone,

When offboarding a user we don't delete their OneDrive site.

I normally use SharePoint module to remove any permissions inside that OneDrive site. But that means I add an additional user as site admin.

I want to change this to the Graph module, but it doesn't seem to be as simple as I thought. I was able to get the user's default drive and I also was able to list all children items and I found which ones have shares option. the thing is I need something that mimics the old script i.e., getting the list of all permissions in the site and remove them.

In the end my question is this - How do I transform this: ($A = get-sposite (OD); get-spouser -site $a.url | foreach {remove-spouser -loginname $_.loginname -site $a.url}) To MgGraph?

Thanks, Rahamim.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,483 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
OneDrive Management
OneDrive Management
OneDrive: A Microsoft file hosting and synchronization service.Management: The act or process of organizing, handling, directing or controlling something.
1,443 questions
{count} votes

Accepted answer
  1. Vasil Michev 116.8K Reputation points MVP
    2023-07-27T15:45:28.8233333+00:00

    Graph does not expose SPO users directly, so you have to work with the permissions. Here's a sample script I wrote a while back that you can use as starting point: https://github.com/michevnew/PowerShell/blob/master/Graph_ODFB_remove_all_shared.ps1


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.