Add link to SharePoint Document Library to OneDrive programmatically with PowerShell or PA

Copper Contributor

Hello, 

 

I have a document library on a SharePoint Online Site that needs to be added as a shortcut in each user's OneDrive. 

 

Obviously, you can do this individually as the user, but I would like to add this link to each user's OneDrive now, and every time a new user account is created in the future(Will take care of this later). This is required as the leadership for my organization wants users to be able to view the library from their file explorer, but open the file in their browser. (Add Shortcut to OneDrive functionality). The Sync functionality is not acceptable. 

 

CamCov_0-1685996507761.png

The "1C" folder here was added by clicking the "Add Shortcut to OneDrive" button on the SPO Document library itself. I would like to achieve the same result, just programmatically for each user. 

 

Any advice is greatly appreciated. I am aware of how to create new files in Power Automate and PowerShell, but cannot seem to create the same link as achieved with the "Add Shortcut to OneDrive" button.

 

Thank you in advance for your time,
Cam

6 Replies
Hello, I appreciate your help, but this describes the Sync functionality which behaves differently than the shortcut functionality.
To add a link to a SharePoint Document Library to OneDrive programmatically using PowerShell, you can utilize the SharePoint PnP PowerShell module. Here's an example script: powershell Copy code # Install the SharePoint PnP PowerShell module if not already installed Install-Module -Name SharePointPnPPowerShellOnline -Force # Connect to SharePoint Online Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Credentials (Get-Credential) # Define the necessary variables $documentLibraryName = "Documents" $documentLibraryRelativeUrl = "/sites/yoursite/Shared Documents" # Relative URL of the document library $linkName = "Shared Documents Link" $linkUrl = "https://yourtenant.sharepoint.com/sites/yoursite/Shared Documents" # Create the link in the OneDrive Add-PnPLink -List $documentLibraryName -WebRelativeUrl $documentLibraryRelativeUrl -Title $linkName -Url $linkUrl Make sure to replace the following placeholders with your actual information: "https://yourtenant.sharepoint.com/sites/yoursite": Replace with the URL of your SharePoint site. "Documents": Replace with the name of your document library. "/sites/yoursite/Shared Documents": Replace with the relative URL of your document library. "Shared Documents Link": Replace with the desired name for the link in OneDrive. "https://yourtenant.sharepoint.com/sites/yoursite/Shared Documents": Replace with the URL of the SharePoint document library. Once you've updated the script with the correct information, you can run it in PowerShell to create the link in OneDrive pointing to the SharePoint Document Library.
Yeha unfortunately there's nothing native that supports to push it to all, so it has to be a script and it's gonna be abit of a hassle.
What you can try this module, I've not tried it myself:

https://github.com/derpenstiltskin/onedriveshortcuts


@Lalit
I'm guessing ChatGPT response ? 🙂 As Add-PnPLink doesn't exist
Add-PnpLink is not part of any cmdlet. ChatGPT is great but often inaccurate, please test your solutions before replying to people.
The best option to achieve this is to use a third-party scalable utility. I have found IAM Cloud Drive Mapper works the best. Zee Drive is another option, and what both do is aggregate based on your permissions, which SharePoint site you have permission to, and you can map them as a single Drive letter for your user base automatically. In addition, you can map OneDrive as a separate drive letter as well. Check it out: https://www.iamcloud.com/cloud-drive-mapper/