Windows Tutorials

Install OneDrive using Group Policy and PowerShell

In this tutorial you will learn how to install OneDrive using Group Policy and PowerShell. By the end of this tutorial, you would have successfully deployed OneDrive to all end user devices during computer startup.

Task Details

  1. Download OneDrive
  2. Create PowerShell Script
  3. Create and Deploy GroupPolicy

Task 1: Download OneDrive

1. On your Domain Controller Download OneDrive

2. Place the OneDriveSetup.exe in your netlogon path.

Task 2: Create PowerShell Script

 1. Open Notepad.exe

2. Copy the script below and place it into Notepad.

$ErrorActionPreference = "SilentlyContinue"

# LOGGING INITIALISATION
$logSource = "OneDrive Per-Machine Deployment"
if (![System.Diagnostics.EventLog]::SourceExists($logSource)){
        new-eventlog -LogName Application -Source $logSource
}
# END OF LOGGING INITIALISATION

# CONFIGURATION DETAILS GO HERE

# Specify the location of the OneDriveSetup.exe
$installationSource = "\\Network\Path\Here"
$destinationPath = "C:\Program Files (x86)\Microsoft OneDrive"
$installedVersion = (Get-Command "$destinationPath\OneDriveSetup.exe").FileVersionInfo.FileVersion

try{
    $ErrorActionPreference = "Stop"
    $targetVersion = (Get-Command "$installationSource\OneDriveSetup.exe").FileVersionInfo.FileVersion
} catch{
    write-eventlog -LogName Application -Source $logSource -EntryType Error -EventId 900 -Message "Unable to determine target OneDrive version - check network connectivity or existence of deployment files."
    Exit
}

$ErrorActionPreference = "SilentlyContinue"

# END CONFIGURATION DETAILS

# START OF EVENT LOGS

if ($targetVersion -ne $installedVersion){
    write-eventlog -LogName Application -Source $logSource -EntryType Information -EventId 1 -Message "Microsoft OneDrive not installed or out of date. Installed version: $installedVersion; target version: $targetVersion. Installation starting..."

    if (Test-Path ($destinationPath)){
        Remove-Item $destinationPath -recurse
        write-eventlog -LogName Application -Source $logSource -EntryType Information -EventId 2 -Message "Existing OneDrive installation removed"
    }

    & "$installationSource\OneDriveSetup.exe" /allusers

    write-eventlog -LogName Application -Source $logSource -EntryType Information -EventId 5 -Message "OneDrive installation complete"
}

# END OF EVENT LOGS

3. In the powershell script locate $installationSource = “\\Network\Path\Here” and enter your own network path to the netlogon.

4. Save the Notepad file as OneDriveInstaller.ps1 and place it into your netlogon.

Task 3: Create and Deploy Group Policy

1. Open Group Policy Management on your server.

2. Locate Group Policy Objects, right click it and select New from the menu.

3. Enter the name OneDriveInstaller and click ok.

4. Locate the newly created policy OneDriveInstaller, right click it and select Edit from the menu.

5. Expand to Scripts (Startup/Shutdown). Computer Configuration > Policies > Windows Settings >

6. Right click Startup and click Properties from the menu.

7. Click the PowerShell Scripts tab. Click the Add button and afterwards drill down to the netlogon path where you placed your PowerShell script and then add it. Make sure to select ( Run Windows PowerShell script first ) from the dropdown and then click Apply.

8. Place your OneDriveInstaller policy into the OU where your user workstations are located. 

9. Push group policy update to all computers, at the next reboot/startup OneDrive will have been installed using Group Policy and PowerShell.

How To Manage OneDrive With Group Policy

I hope this article was helpful, if you have any questions please feel free to contact me. If you would like to be notified of when I create a new post you can subscribe to my blog alert.

author avatar
Patrick Domingues

1 Comment

Leave a Comment

Stay Informed

Receive instant notifications when new content is released.