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

odopen://launch

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:

odopen://sync/?siteId=SiteID_HERE&webId=WebID_HERE&listId=ListID_HERE&userEmail=UserEmail_HERE&webUrl=WebURL_HERE

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)

tenantId=97a51cde%2D8b93%2D4ebb%2Db4a9%2Dcfa0255702a8&siteId=%7B3f1292bb%2D3a51%2D4794%2Dab48%2D2c1365a18fe7%7DwebId=%7B7b3f1da9%2Dac4f%2D4fc0%2Db722%2D3b895621e25f%7D&listId=%7B48B09FE4%2EBFAE%2D41BD%2D847B%2D209755896E96%7D&webUrl=https%3A%2F%2Famericanrampcompanyc%2Esharepoint%2Ecom%2Fsales&version=1

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

odopen://sync/?siteId=%7B3f1292bb%2D3a51%2D4794%2Dab48%2D2c1365a18fe7%7D&webId=%7B7b3f1da9%2Dac4f%2D4fc0%2Db722%2D3b895621e25f%7D&listId=%7B48B09FE4%2EBFAE%2D41BD%2D847B%2D209755896E96%7D&userEmail=UserEmail_HERE&webUrl=https%3A%2F%2Fawesomecompany%2Esharepoint%2Ecom%2Fsales&version=1

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

odopen://sync/?siteId=%7B3f1292bb%2D3a51%2D4794%2Dab48%2D2c1365a18fe7%7D&webId=%7B7b3f1da9%2Dac4f%2D4fc0%2Db722%2D3b895621e25f%7D&listId=%7B48B09FE4%2EBFAE%2D41BD%2D847B%2D209755896E96%7D&userEmail=anthony%40awesomecompany%2Ecom&webUrl=https%3A%2F%2Fawesomecompany%2Esharepoint%2Ecom%2Fsales&version=1&listTitle=Customers&webTitle=Sales

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



.SYNOPSIS
Automaps the Onedrive client to sync with a sharepoint library

.DESCRIPTION
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 tenantname.sharepoint.com/ in front of it if it's the default site, or tenantname.sharepoint.com/sites/SITENAME for any other site.
If the _api data is hard to read, use a tool like https://codebeautify.org/xmlviewer

.PARAMETER siteid
_api/web
Search for "D:Id", here you will find the SiteID Guid

.PARAMETER webid

.PARAMETER listid
_api/web/Lists/getbytitle('NAMEOFTHELIBRARY')
Search for "D:Id", here you will find the ListID Guid

.PARAMETER URL
_api/web
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

.EXAMPLE

.\SharePoint_Automapping.ps1 -siteid GUID -webid = "GUID" -listid = "GUID" -URL https://company.sharepoint.com/ -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=https://company.sharepoint.com/&webtitle=Company&listtitle=Documents"

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

#>
param(
[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){
#DoNothing
} else {
start "odopen://sync/?siteId=$siteid&webId=$webid&listId=$listid&userEmail=$upn&webUrl=$URL&webtitle=$webtitle&listtitle=$listtitle"
}


References:

https://www.cyberdrain.com/automatically-mapping-sharepoint-sites-in-the-onedrive-for-business-client/?unapproved=27966&moderation-hash=2feca26eed3a0023c9ac17f851a66020#comment-27966
https://docs.microsoft.com/en-us/onedrive/deploy-on-windows
https://www.spjeff.com/2019/09/22/odopen-onedrive-open-protocol/
https://blog.russmax.com/automatically-deploy-onedrive-for-business-libraries/
https://docs.microsoft.com/en-us/archive/blogs/steverac/deploying-onedrive-for-business-an-example