Synchronize SharePoint sites with Intune & PowerShell

I recently spent some time with my colleague and frequent collaborator Steven Hosking. We spoke about a solution I came up with to synchronize SharePoint sites to devices using PowerShell & Intune.

This is something I’ve had in my drafts for quite a while, but it kept ending up being too long to write about. As it turns out, Steve ( and Adam) runs a very valuable and informative youtube channel that is dedicated to everything that is “Intune”.

As the solution I wrote for this is directly linked with Intune, we figured it’d be perfect for the channel. We decided to film this little video to show how my solution works better than the official one provided by Microsoft.

To summarize everything in the video:

  • SharePoint sites can be synchronized natively through Intune Administrative Template Policies
  • The native policy has a URI character limit which is very easy to hit
  • Capturing the details required to sync SharePoint sites is very easy using Chrome / Edge Chromium
  • Using PowerShell can overcome current limitations with the native policy solutions.

Here is a link to the code mentioned in the video – if anyone wants further info, please let me know!

Enjoy!

– Ben

13 comments

  1. Sami Karhula Reply
    March 25, 2020 at 11:46 am

    Hi, Thanks for sharing information. I PS script work on intune to deploy SPO site automatically. SPO site shows on test computer but Intune portal show error on deploy PS Script. Did you get this issue? SiteID, WebID, listID is taken same way what is on video.

  2. Humberto Jorquera Reply
    April 5, 2020 at 10:53 am

    Hi Sami, seems like I had the same issue last night. I’ll give it another try tonight, I’m not sure about what am I doing wrong.

  3. Humberto Jorquera Reply
    April 5, 2020 at 11:40 am

    Hey mate,

    I just made it work, in my the error was quite stupid.
    I just followed the video without truly understanding what Ben was explaining, and I converted the parameters in the hash table into variables (minute 26:24 in the video), Ben did this for demonstration purposes as he wasn’t gin to run the entire function, but hen you intend to push this script via intune, you only need to change the value of the parameters but lave the parameter names alone.

    • Sami Karhula Reply
      April 6, 2020 at 7:30 am

      Hi,

      I only change params below. Not convert those to variables as a video. Still get same error. Library synced without problem but intune portal shows failed status.
      try {
      #region Sharepoint Sync
      [mailaddress]$userUpn = cmd /c “whoami/upn”
      $params = @{
      #replace with data captured from your sharepoint site.
      siteId = “{00000000-0000-0000-0000-000000000000}”
      webId = “{00000000-0000-0000-0000-000000000000}”
      listId = “{00000000-0000-0000-0000-000000000000}”
      userEmail = $userUpn
      webUrl = “https://example.sharepoint.com”
      webTitle = “Title”
      listTitle = “FolderName”
      }

  4. Matt Davies Reply
    August 25, 2020 at 12:54 pm

    Hi,
    I’ve gotten this to run successfully through intune syncing a site and document library following the F12 sync parameter capture. If I try to sync another site and doc library on the same site using the same method it fails even though the SiteID, webURL and webTitle are different between the two URI’s in the two scripts. The local onedrive reports that the site is already sync’d.

    Are you aware of this and would you have any suggestion as how to get around it please?
    Many thanks

    • Ben Reply
      September 1, 2020 at 9:30 am

      I’m unable to replicate this – as long as the odopen uri is formed correctly, you should be able to sync as many unique folders as you want.

  5. Steve Reply
    September 18, 2020 at 10:48 am

    Hi Ben,

    Are then any prerequisites to run this script, should I be able to run it locally before running in Intune? Sorry for the dumb question , I am not a PS guru but have a pressing need for this. I have collected the data from F12 and when I run the script locally it hangs and also fails on Intune.

    • Ben Reply
      September 20, 2020 at 11:49 pm

      No pre-reqs aside from making sure you add the correct parameter values for your environment and make sure you have OneDrive for business installed. If you are having issues, the easiest way to troubleshoot is to use the script to build the odopen url and just pasting it into a run command – end of the day that’s all the script is doing.

  6. Victor Reply
    September 30, 2020 at 8:10 pm

    Hi Ben, thanks for the work you share with us.

    A few months ago we started using your script and it worked perfectly.
    A few days ago we started having problems. When run: start-process -filepath $ ($ uri.ToString ()) -ErrorAction SilentlyContinuestart-process nothing happens.
    If we run directly from powershell, nothing happens. If we copy the url and paste it into the browser, it works fine.
    Do you know if there is any problem running odopen from powershell?

    Thank you

  7. Pankaj Reply
    October 10, 2020 at 4:30 pm

    Hello Ben,

    Thanks for such a wonderful script. It works like charm. The only thing I noticed is that this script won’t load when a user logs into the computer for the first time. This is prob because users’ OneDrive hasn’t been loaded properly and Endpoint manager pushes the script within first 5 seconds.
    So the workaround is to log-in the user twice and then the script works like charm (obv this is for a new user).
    This is very helpful instead of creating an administrative template which normally takes up to 8hrs.

  8. Michael David Street Reply
    October 22, 2020 at 12:50 am

    Am I missing something here? Is this the same as “[uri]::UnescapeDataString()” where you put the copied link in between the brackets?

    Found this video to be really useful though because I hadn’t made the connection that Group Policies were what I was actually looking at in Intune.

  9. Michael Reply
    November 29, 2020 at 12:49 am

    Works great! Was looking for a function to automap Sharepoint libraries to my customers for a long time now. Thank you very much!

  10. Michael Reply
    November 30, 2020 at 5:39 am

    I can’t get multiple document libraries to sync through Intune. When i run the Powershell scripts manually they all work. But only one of the uploaded will be deployed via Intune. Suggestions? Only the deployed script is seen in the logs as well and no errors on the rest what I can see.

Leave A Comment Cancel reply

Please be polite. We appreciate that. Your email address will not be published and required fields are marked