Automatically mapping SharePoint sites in the OneDrive for Business client

Microsoft recently announced that the OneDrive for business client will support automatically mapping SharePoint sites – Which is something I’ve been working on to script for some time now. Automapping sites will be a great benefit for migrations where users are saying goodbye to the good old file system, and hello to SharePoint online. Combined with Files on Demands most users won’t even know the difference.

The only sad part about it is that my pretty cool logon script will become useless fairly soon, anyway I’m sharing this to everyone. Its still in a pretty unfinished state, but it might help you if you are currently struggling with this:

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.
$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" 

3 thoughts on “Automatically mapping SharePoint sites in the OneDrive for Business client

  1. Mr J

    Nice script and description, but I am still having trouble finding some of the IDs.

    Browsing this team site page that I want to sync
    Gives me the possibility to get d:Id, which will be the siteID

    Browsing the document library of the team site page'Document‘)
    Returns another d:ID, which would be ListID

    But where can I find the webID?

    I can brows this endpoint of the api

    But it gives me the same ID as the siteID

    Can you give me a hint? /J


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.