Migrate your OneDrive for Business to Per Machine installation (With or without source files using SCCM and Powershell)

Introduction

Installing the OneDrive for Business client on a per machine basis is an often requested feature and for good reasons. OneDrive in it’s current state in the production ring, is installing into the users profile in %localappdata%, and for equally good reasons that is often not desired by enterprises.

Now, Microsoft has finally given us an option, allowing us to install OneDrive for the device into %programfiles(x86)%. The option is currently in preview and all the juicy details are found here: https://docs.microsoft.com/en-us/onedrive/per-machine-installation

PS. Credit where due: I was inspired by Per Larsen’s post on doing the same with Microsoft Intune and like many times before, this brought me to doing something on my own for the sharing and learning experience. Enjoy. 🙂

Powershell

The magic lies in the Powershell script found in the very end of the post.

The script basically comes with 2 options: Install with or without source files using the parameter -NoSourceFiles or -SourceFiles

Needless to say, using the -NoSourceFiles parameter downloads the OneDriveSetup.exe directly from Microsoft and stores it into Windows\Temp from where it also is installed.

Before installation

This is the familiar scenario where OneDrive is installed in the users profile. This is how it looks prior to the installation in my end:

After installation

And below illustration is OneDrive after the installation. Notice the desired location in %programfiles(x86)%. Lovely!

Putting to use with ConfigMgr

Using the script with ConfigMgr is straightforward. The easiest approach is obviously using a package with source files similar to below illustration:

And with that package, create a program running the actual script:

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File .\Migrate-OneDrivePerMachine.ps1 -NoSourceFiles

The Actual Script

Copy below loveliness and save it as Migrate-OneDrivePerMachine.ps1

The script does following in headlines:

  • If used with -NoSourceFiles parameter, the script downloads the OneDriveSetup.exe from Microsoft
    • Store the download into Windir\Temp
    • Runs the installation from Windir\Temp
    • Waits for the OneDriveSetup.exe process to complete
    • Configures OneDrive to insiders update ring (needed in order to receive future updates for per machine installation)
  • If  used with -SourceFiles parameter, the script assumes local source files
    • That means that the OneDriveSetup.exe should be put next to the script in the same directory
    • And then the script does roughly the same

ENJOY 🙂

9 thoughts on “Migrate your OneDrive for Business to Per Machine installation (With or without source files using SCCM and Powershell)”

  1. But what if couple user will log in to that machine?
    If is stored on %appdata% – it’s assigned to one user. What if you move to program files? There will be sync conflicts?

    • This is a per machine installation and thus any current and future user profiles will use the installation made in programfiles. No conflicts. The application in %localappdata% will be retired for each user logging in 🙂

  2. I couldn’t get it to work without the source files. I get an “Error in downloading OneDriveSetup.exe” message when I try running it from an Administrator Powershell cmd window. Works if I provide the exe.

  3. Is there a way to hide the “Preparing OneDrive for first use.” dialog from appearing during installation? It also has an X at top right which users can click and thus make the installation fail.

    We would like to deploy this to all our workstations as a ConfigMgr Application, replacing the old version which installs itself to all users separately, which is annoying especially on classroom workstations where that happens at each logon.

  4. Morning,
    I am trying to roll this out via GPO using the -SourceFiles with the onedrive exe in the same folder, I have tried a bat file and also just the ps1 script, but nothing seems to happen. if i run it manually when logged it it works perfect. any ideas?

Leave a Comment

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