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

Valeri Frunze 20 Reputation points

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 ''
$user2 = Get-MgUser -UserId ''
$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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
2,109 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.
976 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,321 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 79,706 Reputation points MVP

    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:

0 additional answers

Sort by: Most helpful