Uninstall OneDrive per user package

Comments

8 comments

  • Brian Gorton

    This works for me, although most stations it throws an error on the first line that the Process wasn't found, but this has removed it for any local Windows accounts that have previously logged on, or for a new user logging on.

    #Import-Module -DisableNameChecking $PSScriptRoot\..\lib\force-mkdir.psm1
    #Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1

    echo "73 OneDrive process and explorer"
    taskkill.exe /F /IM "OneDrive.exe"
    #taskkill.exe /F /IM "explorer.exe"

    echo "Remove OneDrive"
    if (Test-Path "$env:systemroot\System32\OneDriveSetup.exe") {
        & "$env:systemroot\System32\OneDriveSetup.exe" /uninstall
    }
    if (Test-Path "$env:systemroot\SysWOW64\OneDriveSetup.exe") {
        & "$env:systemroot\SysWOW64\OneDriveSetup.exe" /uninstall
    }

    echo "Disable OneDrive via Group Policies"
    mkdir -force "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" 
    sp "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" "DisableFileSyncNGSC" 1

    echo "Removing OneDrive leftovers trash"
    rm -Recurse -Force -ErrorAction SilentlyContinue "$env:localappdata\Microsoft\OneDrive"
    rm -Recurse -Force -ErrorAction SilentlyContinue "$env:programdata\Microsoft OneDrive"
    rm -Recurse -Force -ErrorAction SilentlyContinue "C:\OneDriveTemp"

    echo "Remove Onedrive from explorer sidebar"
    New-PSDrive -PSProvider "Registry" -Root "HKEY_CLASSES_ROOT" -Name "HKCR"
    mkdir -Force "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
    sp "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0
    mkdir -Force "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
    sp "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" "System.IsPinnedToNameSpaceTree" 0
    Remove-PSDrive "HKCR"

    echo "Removing run option for new users"
    reg load "hku\Default" "C:\Users\Default\NTUSER.DAT"
    reg delete "HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDriveSetup" /f
    reg unload "hku\Default"

    echo "Removing startmenu junk entry"
    rm -Force -ErrorAction SilentlyContinue "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"

    #echo "Restarting explorer..."
    #start-process "explorer.exe"

    echo "Wait for EX reload.."
    sleep 15

    echo "Removing additional OneDrive leftovers"
    foreach ($item in (ls "$env:WinDir\WinSxS\*onedrive*")) {
        Takeown $item.FullName
        rm -Recurse -Force $item.FullName
    }

    However, and I may be preaching to the choir, check your Windows Updates so they don't re-enable it, as well as when/if you do a Feature Update (ex. 1903 to 1909/2004), it will enable almost all disabled Windows built-in applications.

     

    0
    Comment actions Permalink
  • Kdave

    Wouldn't GPO work better at this?

    0
    Comment actions Permalink
  • Jason Riggs

    I may be completely wrong, but the GPO settings will prevent future setups, but not erase old setups.

    0
    Comment actions Permalink
  • Jason Riggs

    The script actually did not work for me, again except for the currently logged in user. When i attempted to run this against a machine that had previous installations, It errored and actually added a new instance under the local admin account. 

     

    0
    Comment actions Permalink
  • Kdave

    I used decrapify (if you google it, you should be able to find it) and modified it on what I wanted installed and not installed. After each win10 workstation I run new workstation job that run the decrapify script and bunch of other things that i want installed.

    0
    Comment actions Permalink
  • Jason Riggs

    Again...and I may be wrong, this works great to prevent future installs, but does it remove existing installations for all users?

    0
    Comment actions Permalink
  • Kdave

    good question, I haven't tested that. Can you be the beta tester :)

     

    0
    Comment actions Permalink

Please sign in to leave a comment.