OneDrive Machine Install Script

This is a blog about a script which removes OneDrive Personal and installs OneDrive Machine (All users) Install. You can use this if you want to deploy OneDrive on Windows Virtual Desktop for example.

Script Syntax

$Processes = Get-Process
If ($Processes.ProcessName -Like "OneDrive") {

    Write-Host OneDrive is Running and will be shutdown

    taskkill /f /im OneDrive.exe

    If (Test-Path C:\Windows\SysWOW64\OneDriveSetup.exe){
        
        Write-Host "OneDrive installation found, OneDrive Personal will be removed"

        C:\Windows\SysWOW64\OneDriveSetup.exe /uninstall

            If (Test-Path C:\Windows\SysWOW64\OneDriveSetup.exe){
        
            Write-Host "OneDrive Machine installation found, OneDrive Machine Install will be installed"

            C:\Windows\SysWOW64\OneDriveSetup.exe /allusers

            }
            Else{
            Write-Host "OneDrive Machine Installation not found"
    }  
    }
    Else{
        Write-Host "OneDrive Personal Installation not found"
    }

}
Else{
    Write-Host OneDrive is not running
           
            If (Test-Path C:\Windows\SysWOW64\OneDriveSetup.exe){
        
            Write-Host "OneDrive Machine installation found, OneDrive Machine Install will be installed"

            C:\Windows\SysWOW64\OneDriveSetup.exe /allusers

            }
            Else{
            Write-Host "OneDrive Machine Installation not found"
            }
}

Script Example

Firstly, you can run the script on any machine. It does not matter if OneDrive is running, already installed or not installed. The OneDrive setup located in:

C:\Windows\SysWOW64\OneDriveSetup.exe

Is always available in Windows 10.

When you run the script this is the output:

OneDrive machine install script deployment

References

WVD Delete hostpool script

Flow triggered DevOps Build

OneDrive Microsoft Docs

1 thought on “OneDrive Machine Install Script”

Leave a Comment