The Problem

So you want to move your files to SharePoint, great! But your users don’t understand sharepoint, don’t wanna learn sharepoint and just want their file explorer experience.

There are a few ways we can go about syncing libraries for our users. We can set a group policy or Intune configuration to automatically sync a SharePoint library however there are some big caveats with this such as a 250~ url character limit. We could also try and provide instructions to have our users sync it themselves or we can remote in and do it for them. But say you just have a few users that need a library. Can we just make a simple PS script to sync the library without going through a GPO? Sure we can!

Lets Automate

First, we need to get the sync link. To do that go to the SharePoint document library you want to sync, and fire up your browser developer tools. Go to Network, Select All. Click the Sync button and grab the URL


Now fire up your favorite script editor.

We need to set some variables. First we need to get the users email address. We can do this by looking at the OneDrive for Business registry key.

Then specify the SharePoint Site Name

$onedrivepath = "registry::HKCU\SOFTWARE\Microsoft\OneDrive\Accounts\Business1"
$email = (Get-itemproperty $onedrivepath).useremail
$email = $email.replace('@','%40')
$email = $email.replace('.', '%2E')
$TenantName = (Get-itemproperty $onedrivepath).displayname
$ODParentFolder = (get-itemproperty $onedrivepath).userfolder | split-path
$site = #Name of Sharpoint Site

Next, take the URL you copied earlier. Remove the string starting after sync? up to &siteid. Replace with userEmail=$email store as $URL variable. It should look like this when you are done

$url = "odopen://sync?userEmail=$email&siteId=%7Bae1e23cf%2Ddf19%2D4812%2D9950%2Debb6df6c782e%7D&webId=%7B60c35ac0%2Db7e0%2D40ae%2D8a4f%2D31cf7f0aea48%7D&webTitle=Carol%20Barnes%20Memorial&webTemplate=64&webLogoUrl=%2Fsites%2FCarolBarnesMemorial%2F%5Fapi%2FGroupService%2FGetGroupImage%3Fid%3D%276bd4e65d%2D3445%2D4738%2Dac3f%2Df18836d977a5%27%26hash%3D637528692054184638&webUrl=https%3A%2F%2Fjustgeeks%2Esharepoint%2Ecom%2Fsites%2FCarolBarnesMemorial&onPrem=0&libraryType=3&listId=%7BF024B7B4%2DD3AA%2D422E%2D85B8%2DC3FE2AEA9F02%7D&listTitle=Documents&scope=OPENLIST"

Last lets just add a little logic to prevent adding the document library if it is already synced.

$TestSyncedLibrary = GCI $ODParentFolder\$tenantname -directory | where name -like "$site*"

if ($TestSyncedLibrary.Count -lt 1)
	Start-Process $url

Now just upload the script to Intune and set to run as user, or use your favorite RMM tool. You could also deploy this with a login script or use a scheduled task to run at user login.

Just a shell of an idea.