Programmatic way to add a shortcut to OneDrive for users?

Copper Contributor

Would like to add a SharePoint document library shortcut to our users OneDrive account within our organization.   This is in reference to the relatively new feature of "Add shortcut to OneDrive".  


Would like to do this automatically.  Is this possible via powershell or any API?


9 Replies

You can do that in an old fashioned way via Group Policy
But read it carefully, there is a limit:  5000 Files/folders and 1000 devices


I do not know, but I think it's not in the API right now.

If you have more the 1000 Devices (nut users!) , you have to do it as described below,


But You can share a Link to all users from the document folder of the SharePoint Library
And the inform the users, the should go into their OneDrive , Klick on Shared with me. Identify the Folder, Select the folder and the click on Add a ShortCut to My Files. Done

Is that too much for the users?

@Hans Brender From testing, the only issue I see is that the group policy piece did not work for communication sites, only for Team Sites. Can you confirm? Also no PowerShell or Graph API yet? Is that still the case? Thanks

@Liam Cleary So the Group Policy is a technology, which is limited, because this is the root folder (and if you have a lot of documents in this library, you can got in trouble with too many files (300000 is the Limit)

Add to shortcut is a quick thing, each person will do manually and has many advantages.
you may read my last article about Add to OneDrive , what's the difference.

@Hans Brender Because of the limitation of the group policy, would like to script it out, as links in OneDrive, almost a pre-provision process. Users will of course add their own as they see fit, but for day one launch, there needs to be a few auto added. Just intrigued to know if API is available to do it yet.

@jfergus11 Did you find a workable solution for this?

@Daniel Baird 
I have managed to achieve it somehow

You need to register SPO App within Azure AD with Sites.FullControl.All permission, and look up shortcut body by inspecting browser dev tool (just to get the correct payload per folder). Add a link from browser and look for "children" POST API Call and copy the payload. There are possibly other ways to reconstruct the correct data, I was lazy so I looked up these values. 

$UPN = ""
$Token = (Get-MsalToken -TenantId tenantID -ClientId ClientID -ClientCertificate (get-item Cert:\LocalMachine\My\CertThumbprint) -scopes "").AccessToken
$URI = "$UPN/items/root/children"

$Dokumenty = @(
    @{Site1 = @"
    @{Site2 = @"
    @{Site3 = @"

$Dokumenty | % { Invoke-RestMethod -Uri $URI -Headers @{Authorization = "Bearer $Token"} -ContentType 'application/json' -Body $_.values -Method POST}

You need to replace the payloads within $Dokumenty array. Each Folder will be added for that user to OneDrive as Shortcut. Let me know if it worked for you :)

did this work for you?

@Alex Pawlak I tried your solution and I cannot make it work with the App Registration. If I set $Token with the Token from a SharePoint session I have open in my browser, it works.


Can you provide the exact settings you put in the app registration? I selected SharePoint - Sites.FullControl.All (App Only). I don't know what's wrong.

Is there a way to get this working with Multi Geo tenant?
I keep getting error (308) when I try this script with user from another geo location apart from default geolocation.