Forum Discussion
CamCov
Jun 05, 2023Copper Contributor
Add link to SharePoint Document Library to OneDrive programmatically with PowerShell or PA
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 l...
Lalit Mohan
Jun 06, 2023Iron Contributor
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.
- CamCovJun 06, 2023Copper ContributorAdd-PnpLink is not part of any cmdlet. ChatGPT is great but often inaccurate, please test your solutions before replying to people.