Repository: rclone/rclone (language: go)

Issue:
OneDrive Impersonation
<!--

Welcome :-) We understand you are having a problem with rclone; we want to help you with that!

If you've just got a question or aren't sure if you've found a bug then please use the rclone forum:

    https://forum.rclone.org/

instead of filing an issue for a quick response.

If you are reporting a bug or asking for a new feature then please use one of the templates here:

    https://github.com/rclone/rclone/issues/new

otherwise fill in the form below.

Thank you

The Rclone Developers

-->


#### Output of `rclone version`
1.56.1


#### Describe the issue
Feature Request:  OneDrive impersonation.  We have a need for migration purposes to utilize Impersonation.





Discussion / hints:
not directly impersonation, but as a sharepoint admin, they can grant themselves to users' onedrvive using GUI or PowerShell, I have been playing around with `rclone config` and trying to discover the OneDrive site I have access to no avail. 

URL pattern is https://{tenant}-my.sharepoint.com/personal/{user_name_domain_tld}/

https://community.movebot.io/hc/en-us/articles/4402325031695-Granting-Admin-Access-to-OneDrive-with-SharePoint
https://pnp.github.io/powershell/cmdlets/Connect-PnPOnline.html
@hjkimbrian that is useful info. Do you fancy adding this to the rclone docs?

https://github.com/rclone/rclone/blob/master/docs/content/onedrive.md

(click the pencil icon or do a PR in the usual way)
For those that come later wanting to do this, here are the steps that worked for me:

1. In [Microsoft 365 Admin Center](https://admin.microsoft.com), open each user you need to "impersonate" and go to the OneDrive section. There is a heading called "Get access to files", you need to click to create the link, this creates the link of the format `https://{tenant}-my.sharepoint.com/personal/{user_name_domain_tld}/` but also does something in the backend to give you permission
2. Then in powershell run the following commands:
```console
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
Import-Module Microsoft.Graph.Files
Connect-MgGraph -Scopes "Files.ReadWrite.All"
# Follow the steps to allow access to your admin user
# Then run this for each user you want to impersonate to get the Drive ID
Get-MgUserDefaultDrive -UserId '{emailaddress}'
# This will give you output of the format:
# Name     Id                                                                 DriveType CreatedDateTime
# ----     --                                                                 --------- ---------------
# OneDrive b!XYZ123                                                           business  14/10/2023 1:00:58 pm

```
3. Then in rclone add a onedrive remote type, and use the `Type in driveID` with the DriveID you got in the previous step. One remote per user. It will then confirm the drive ID, and hopefully give you a message of `Found drive "root" of type "business"` and then include the URL of the format `https://{tenant}-my.sharepoint.com/personal/{user_name_domain_tld}/Documents`

(Yes, I should probably update the OneDrive docs, but that requires a bit more effort than dumping my working commands here, I'll try to come back later after this project to write up nice docs)
@timwsuqld appreciate the writeup - thank you  :-)

If you want to add it to the docs you can do it in your browser from here (click the pencil icon to edit): https://github.com/rclone/rclone/blob/master/docs/content/onedrive.md it is in markdown so your comment above will cut and paste into the docs! (tip: edit your comment to get it back into markdown)

Fix patch:
diff --git a/docs/content/onedrive.md b/docs/content/onedrive.md
index a14b7a79e3ee2..91c8520831d1a 100644
--- a/docs/content/onedrive.md
+++ b/docs/content/onedrive.md
@@ -936,6 +936,28 @@ See the [metadata](/docs/#metadata) docs for more info.
 
 {{< rem autogenerated options stop >}}
 
+### Impersonate other users as Admin
+
+Unlike Google Drive and impersonating any domain user via service accounts, OneDrive requires you to authenticate as an admin account, and manually setup a remote per user you wish to impersonate.
+
+1. In [Microsoft 365 Admin Center](https://admin.microsoft.com), open each user you need to "impersonate" and go to the OneDrive section. There is a heading called "Get access to files", you need to click to create the link, this creates the link of the format `https://{tenant}-my.sharepoint.com/personal/{user_name_domain_tld}/` but also changes the permissions so you your admin user has access.
+2. Then in powershell run the following commands:
+```console
+Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
+Import-Module Microsoft.Graph.Files
+Connect-MgGraph -Scopes "Files.ReadWrite.All"
+# Follow the steps to allow access to your admin user
+# Then run this for each user you want to impersonate to get the Drive ID
+Get-MgUserDefaultDrive -UserId '{emailaddress}'
+# This will give you output of the format:
+# Name     Id                                                                 DriveType CreatedDateTime
+# ----     --                                                                 --------- ---------------
+# OneDrive b!XYZ123                                                           business  14/10/2023 1:00:58 pm
+
+```
+3. Then in rclone add a onedrive remote type, and use the `Type in driveID` with the DriveID you got in the previous step. One remote per user. It will then confirm the drive ID, and hopefully give you a message of `Found drive "root" of type "business"` and then include the URL of the format `https://{tenant}-my.sharepoint.com/personal/{user_name_domain_tld}/Documents`
+
+
 ## Limitations
 
 If you don't use rclone for 90 days the refresh token will


Test patch: