How do I grant read access to a user's OneDrive to another user using Graph PowerShell Module

Valeri Frunze 20 Reputation points
2023-09-05T13:33:43.9433333+00:00

I would like to grant user1 access to user2's onedrive using Graph Powershell module.

all code except the last line executes without errors.

Connect-MgGraph -AccessToken ($accessToken | ConvertTo-SecureString -AsPlainText -Force)
$user1 = Get-MgUser -UserId 'user1@example.com'
$user2 = Get-MgUser -UserId 'user2@example.com'
$drive = Get-MgUserDrive -UserId $user1.Id
New-MgUserDriveRootPermission -DriveId $drive.Id -UserId $user2.Id -Roles 'Read'

The last line produces error and I cannot find documentation to understand what is missing for the request to become valid.

The error is following:

New-MgUserDriveRootPermission_CreateExpanded: Invalid request Status: 400 (BadRequest) ErrorCode: invalidRequest Date: 2023-09-05T13:24:15

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | OneDrive | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Vasil Michev 123.5K Reputation points MVP Volunteer Moderator
    2023-09-05T16:28:35.3333333+00:00

    That cmdlet is used for sharing individual files/folders, it will not work on the drive itself. For your scenario, you will have to add the user as a secondary site collection administrator, an operation which is not currently supported via the Graph. Use one of the methods listed here instead: https://petri.com/4-ways-add-secondary-administrator-onedrive-business/


0 additional answers

Sort by: Most helpful

Your answer

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