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/
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 '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