query on onedrive

Roger Roger 6,671 Reputation points
2024-11-19T21:50:33.16+00:00

Hi All,

I have a user, user1@contoso.com, and I need to determine how many users currently have access to user1's OneDrive. If user1 has shared any files or folders with other users, I want to revoke all their access. Please guide me how to achieve this.

Additionally, I need to grant user2@contoso.com access to user1's OneDrive, which I can achieve using the following syntax:

Set-SPOUser -Site https://contoso-my.sharepoint.com/personal/user1_contoso_com -LoginName user2@contoso.com -IsSiteCollectionAdmin $true
Microsoft Exchange Online
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,226 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,004 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,658 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,305 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Yanli Jiang - MSFT 28,121 Reputation points Microsoft Vendor
    2024-11-20T08:46:35.9266667+00:00

    Hi @Roger Roger ,

    Welcome to Q&A forum!

    If you want to get how many users have access to User 1's OneDrive:

    First, you need to add yourself as an administrator of User 1's OneDrive.

    https://www.sharepointdiary.com/2017/04/gain-admin-permission-to-onedrive-for-business-sites-using-powershell.html

    Non-official, just for reference.

    Then, you can get the Sharing report in User 1's OneDrive.

    Open User1's OneDrive, go to OneDrive settings--More Settings--Run sharing report, and you'll be asked where in the drive you want to save the report. The resulting csv file shows the different ways a file has been shared and with whom.

    https://www.ytria.com/blog/onedrive-sharing-report-for-all-users/

    Non-official, just for reference.

    Finally, if you want to terminate sharing in batches, you can use PowerShell to remove the sharing link.

    Function Remove-OneDriveSharingLink {
        param (   
            $OneDriveURL
            )   
        process {
            Connect-PnPOnline -Url $OneDriveURL 
            $Ctx= Get-PnPContext
    
            $Files= Get-PnPListItem -List "documents"
            foreach( $File in $Files) {       
                $Froles= $File.RoleAssignments
                $Ctx.load($Froles)
                $Ctx.ExecuteQuery()
    
                If($Froles.Count -gt 0) {
                    for ($i = $Froles.Count -1; $i -ge 0 ; --$i){   
                    $Link=$Froles[$i].Member
                    $Ctx.Load($Link)
                    $Ctx.ExecuteQuery()
                    If($Link.title -like "SharingLinks*") {
                        $Froles[$i].DeleteObject()
                    }
                    $Link = $null
                }
                $Ctx.ExecuteQuery()           
                }      
            }
        }
    }
    
    Remove-OneDriveSharingLink -OneDriveURL "https://<tenant>-my.sharepoint.com/personal/<username>_<tenant>_onmicrosoft_com"
    

    It breaks all the links shared, internal or external.

    For more info., please see:

    https://sharepoint.stackexchange.com/questions/278316/how-can-unshare-stop-sharing-of-onedrive-files-and-folders-using-powershell

    The PowerShell command you use to grant User 2 access to User 1's OneDrive is completely correct. The premise is that you have administrator privileges to User 1's OneDrive.

    For your references:

    https://zcusa.951200.xyz/en-us/microsoft-365/admin/add-users/remove-former-employee-step-5?view=o365-worldwide#access-a-former-users-onedrive-documents

    https://techcommunity.microsoft.com/discussions/onedriveforbusiness/onedrive-external-sharing-and-departed-users/130931

    Good day!


    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Alvaro Avila 165 Reputation points
    2024-12-03T13:22:46.33+00:00

    Here is a free and open source app that help you out to generate a report of all permissions in a Site/OneDrive.

    https://github.com/Barbarur/NovaPoint

    This is the documentation about the permissions report; https://github.com/Barbarur/NovaPoint/wiki/Solution-Report-PermissionsReport

    0 comments No comments

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.