OneDrive must be installed first.  Also be sure to sync your OneDrive account by going to this link in your browser:


I found a great script that once you set all the strings when a user executes it the document will start syncing.
Read on to find out how to find the strings needed or click here to skip to the bottom for the script.

Go to the Library you want to Sync in SharePoint and click Sync.  Click Cancel on this:

Click Copy library ID and paste the info into Notepad. (I did this in Firefox so it may look a little different for you).

Microsoft says use this format:


Using this format did work however it defaulted the name of the directory to Company Name – Documents like so:

I did not like that so I added the following at the end of Microsoft’s link:

odopen://sync/?siteId=SiteID_HERE&webId=WebID_HERE&listId=ListID_HERE&userEmail=UserEmail_HERE&webUrl=WebURL_HERE&listTitle=Company Name&webTitle=Documents

Here is my example.  Below in bold is the content I pulled out of the Copy library ID link at the beginning of this post:
(Go here to find the encoded URL characters to use when creating your url)


I then plugged those values into the formula Microsoft gave me:


Next was adding the correct email address and the name I wanted:
(@ translates to %40 and . translates to %2E)


I then copied this link into a shortcut file by right clicking anywhere on desktop>New>Shortcut:

Paste your link in then click Next:

Type a name you want then click Finish:

Now when you double click on the shortcut it should open OneDrive and ask what folders you want to sync
Also you can verify the name is correct Sales – Customers.  Click Start Sync

Now it shows up in your File Explorer with the name you wanted

This below script is a PowerShell script so name the file .ps1

One handy way to execute the below script in a bat file:
Powershell.exe -executionpolicy remotesigned -File “Path to .ps1 file”

You may want to copy past this into notepad first to strip out any html

Automaps the Onedrive client to sync with a sharepoint library

Run the script with all mandatory parameters

In order to use the parameters you need to fetch them from the applicable site.
Every _api link should have in front of it if it's the default site, or for any other site.
If the _api data is hard to read, use a tool like

Search for "D:Id", here you will find the SiteID Guid


Search for "D:Id", here you will find the ListID Guid

Search for "D:web", here you will find the SiteID Guid

.PARAMETER webtitle
Set this to the name of the organisation

.PARAMETER listtitle
Set this to the name of the library


.\SharePoint_Automapping.ps1 -siteid GUID -webid = "GUID" -listid = "GUID" -URL -webtitle Company -listtitle Documents

which will create the following link for the OneDrive app:

start "odopen://sync/?siteId=GUID&webId=GUID&listId=GUID&userEmail=$upn&webUrl="

In order to retrieve the _api info you need to log in to the tenant, no admin rights are necessary.

[String]$siteid = "%7B3f1292bb%2D3a51%2D4794%2Dab48%2D2c1365a18fe7%7D",
[String]$webid = "%7B7b3f1da9%2Dac4f%2D4fc0%2Db722%2D3b895621e25f%7D",
[String]$listid = "%7B48B09FE4%2EBFAE%2D41BD%2D847B%2D209755896E96%7D",
[String]$URL = "https%3A%2F%2Fawesomecompany%2Esharepoint%2Ecom%2Fsales&version=1",
[String]$webtitle = "Sales",
[String]$listtitle = "Customers"

$rand = Get-Random -Maximum 10
sleep $rand
#Sleep is required, if the same script runs at the same time it'll mess up the configuration.
$Version = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID | Select-Object ReleaseID
if($version.releaseID -lt 1709) { break }

$strFilter = “(&(objectCategory=User)(SAMAccountName=$Env:USERNAME))”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = “Subtree”
$objSearcher.PropertiesToLoad.Add(“userprincipalname”) | Out-Null
$colResults = $objSearcher.FindAll()

$UPN = $colResults[0].Properties.userprincipalname
$path = "C:\Users\$($env:username)\Lime Networks BV\Lime Networks - $($listtitle)"
if(Test-Path $path){
} else {
start "odopen://sync/?siteId=$siteid&webId=$webid&listId=$listid&userEmail=$upn&webUrl=$URL&webtitle=$webtitle&listtitle=$listtitle"