Here's a function I wrote and use, and it works both online and offline. For an offline image, you just need to use the -Offline switch with it and it will automatically detect the mount path of the WIM and set it as its working variable. As you can see, how I remove it in its online state has a few more steps in it than most. Code: Function Remove-OneDrive { <# .SYNOPSIS Completely remove Microsoft OneDrive. .DESCRIPTION Completely remove Microsoft OneDrive from either the current online system or from an offline mounted install.wim .PARAMETER Offline Removes OneDrive from an offline mounted install.wim instead of the current online system. .EXAMPLE PS C:\> Remove-OneDrive .EXAMPLE PS C:\> Remove-OneDrive -Offline .NOTES An install.wim must be mounted prior to using the -Offline switch. #> [CmdletBinding()] Param ( [Parameter(HelpMessage = 'Removes OneDrive from an offline mounted install.wim instead of the current online system.')] [switch]$Offline ) Begin { $CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) If (!$CurrentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Warning "This function requires administrative permissions. Please restart Powershell with elevation."; Break } } Process { Function Grant-FileOwnership { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] $Path ) Invoke-Expression -Command ('TAKEOWN /F $Path /A') $ACL = Get-Acl -Path $Path $SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544') $Admin = $SID.Translate([System.Security.Principal.NTAccount]) $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule($Admin, "FullControl", "None", "None", "Allow") $ACL.AddAccessRule($Rule) $ACL | Set-Acl -Path $Path } Function Grant-FolderOwnership { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] $Path ) Grant-FileOwnership -Path $Path ForEach ($Object In Get-ChildItem -Path $Path -Recurse) { If (Test-Path -Path $Object -PathType Container) { Grant-FolderOwnership -Path $Object.FullName } Else { Grant-FileOwnership -Path $Object.FullName } } } Function New-Container { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [string]$Path ) If (!(Test-Path -Path $Path)) { [void](New-Item -Path $Path -ItemType Directory -Force) } } If ($Offline) { If (!(Get-WindowsImage -Mounted)) { Write-Warning "No mounted image detected."; Break } Else { $MountFolder = (Get-WindowsImage -Mounted).MountPath } Write-Host "`nPerforming offline removal of OneDrive." -ForegroundColor Cyan Start-Sleep 3 $OneDrive = "$MountFolder\Windows\SysWOW64\OneDriveSetup.exe" If (!(Test-Path -Path $OneDrive)) { $OneDrive = "$MountFolder\Windows\System32\OneDriveSetup.exe" } Remove-Item -Path $OneDrive -Force Start-Process -FilePath REG -ArgumentList ("LOAD HKLM\WIM_HKLM_SOFTWARE `"$MountFolder\Windows\System32\config\software`"") -WindowStyle Hidden -Wait Start-Process -FilePath REG -ArgumentList ("LOAD HKLM\WIM_HKCU `"$MountFolder\Users\Default\NTUSER.DAT`"") -WindowStyle Hidden -Wait New-Container -Path "HKLM:\WIM_HKLM_SOFTWARE\Policies\Microsoft\Windows\OneDrive" New-Container -Path "HKLM:\WIM_HKLM_SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" New-Container -Path "HKLM:\WIM_HKCU\SOFTWARE\Microsoft\OneDrive" Set-ItemProperty -Path "HKLM:\WIM_HKLM_SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\WIM_HKLM_SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSync" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\WIM_HKLM_SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableMeteredNetworkFileSync" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\WIM_HKLM_SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableLibrariesDefaultSaveToOneDrive" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\WIM_HKLM_SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\WIM_HKCU\SOFTWARE\Microsoft\OneDrive" -Name "DisablePersonalSync" -Value 1 -Type DWord If ((Get-ItemProperty -Path "HKLM:\WIM_HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -ErrorAction SilentlyContinue) -match "OneDriveSetup") { Remove-ItemProperty -Path "HKLM:\WIM_HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup" -Force } If (Test-Path -Path "HKLM:\WIM_HKLM_SOFTWARE\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") { Remove-Item -Path "HKLM:\WIM_HKLM_SOFTWARE\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Force -Recurse -ErrorAction SilentlyContinue } If (Test-Path -Path "HKLM:\WIM_HKLM_SOFTWARE\WOW6432Node\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}") { Remove-Item -Path "HKLM:\WIM_HKLM_SOFTWARE\WOW6432Node\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Force -Recurse -ErrorAction SilentlyContinue } Start-Process -FilePath REG -ArgumentList ("UNLOAD HKLM\WIM_HKLM_SOFTWARE") -WindowStyle Hidden -Wait Start-Process -FilePath REG -ArgumentList ("UNLOAD HKLM\WIM_HKCU") -WindowStyle Hidden -Wait If (Test-Path -Path "$MountFolder\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk") { Remove-Item -Path "$MountFolder\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force -ErrorAction SilentlyContinue } ## The removal of the WinSxS OneDrive items can sometimes cause CheckHealth and ScanHealth to report corruption. ForEach ($Item In Get-ChildItem -Path "$MountFolder\Windows\WinSxS\*onedrive*") { [void](Grant-FolderOwnership -Path $Item.FullName) Remove-Item -Path $Item.FullName -Recurse -Force -ErrorAction SilentlyContinue } } Else { Write-Host "`nStopping all OneDrive Processes." -ForegroundColor Cyan (Get-Process -Name OneDrive) | ForEach-Object -Process { $_.Kill() } Start-Sleep 3 $OneDrive = "$Env:SYSTEMROOT\SysWOW64\OneDriveSetup.exe" If (!(Test-Path -Path $OneDrive)) { $OneDrive = "$Env:SYSTEMROOT\System32\OneDriveSetup.exe" } Write-Host "`nUninstalling OneDrive." -ForegroundColor Cyan Start-Process $OneDrive "/uninstall" -NoNewWindow -Wait Start-Sleep 20 Remove-Item -Path $OneDrive -Force Write-Host "`nRestarting Explorer." -ForegroundColor Cyan (Get-Process -Name explorer).Kill() Start-Sleep 5 Write-Host "`nRemoving OneDrive directories." -ForegroundColor Cyan Remove-Item -Path "$Env:LOCALAPPDATA\Microsoft\OneDrive" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "$Env:PROGRAMDATA\Microsoft OneDrive" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "$Env:SYSTEMDRIVE\OneDriveTemp" -Recurse -Force -ErrorAction SilentlyContinue If ((Get-ChildItem -Path "$Env:USERPROFILE\OneDrive" -Recurse | Measure-Object).Count -eq 0) { Remove-Item -Path "$Env:USERPROFILE\OneDrive" -Recurse -Force -ErrorAction SilentlyContinue } Write-Host "`nDisabling OneDrive Policies." -ForegroundColor Cyan New-Container -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" New-Container -Path "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" New-Container -Path "HKCU:\SOFTWARE\Microsoft\OneDrive" Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSync" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableMeteredNetworkFileSync" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" -Name "DisableLibrariesDefaultSaveToOneDrive" -Value 1 -Type DWord Set-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive" -Name "DisableFileSyncNGSC" -Value 1 -Type DWord Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\OneDrive" -Name "DisablePersonalSync" -Value 1 -Type DWord Write-Host "`nRemoving the OneDrive icon from the Navigation Pane." -ForegroundColor Cyan If (!(Test-Path -Path "HKCR:")) { [void](New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT) } Remove-Item -Path "HKCR:\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path "HKCR:\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Recurse -Force -ErrorAction SilentlyContinue Remove-PSDrive -Name HKCR Write-Host "`nRemoving the OneDrive auto-run hook for: $($Env:USERNAME)" -ForegroundColor Cyan If ((Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") -match "OneDriveSetup") { Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup" -Force } Write-Host "`nRemoving the OneDrive auto-run hook for all new users." -ForegroundColor Cyan [void](Invoke-Expression -Command ('REG LOAD HKLM\DEFAULT_USER "C:\Users\Default\NTUSER.DAT"')) If ((Get-ItemProperty -Path "HKLM:\DEFAULT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") -match "OneDriveSetup") { Remove-ItemProperty -Path "HKLM:\DEFAULT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup" -Force } [void](Invoke-Expression -Command ('REG UNLOAD HKLM\DEFAULT_USER')) Write-Host "`nRemoving the OneDrive Start Menu link." -ForegroundColor Cyan If (Test-Path -Path "$Env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk") { Remove-Item -Path "$Env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force -ErrorAction SilentlyContinue } Write-Host "`nRestarting Explorer." -ForegroundColor Cyan (Get-Process -Name explorer).Kill() Start-Sleep 5 Write-Host "`nUnregistering the OneDrive scheduled task." -ForegroundColor Cyan [void](Get-ScheduledTask -TaskPath '\' -TaskName 'OneDrive*' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false) ## The removal of the WinSxS OneDrive items can sometimes cause CheckHealth and ScanHealth to report corruption. Write-Host "`nRemoving any remaining OneDrive WinSxS folders." -ForegroundColor Cyan ForEach ($Item In Get-ChildItem -Path "$Env:windir\WinSxS\*onedrive*") { [void](Grant-FolderOwnership -Path $Item.FullName) Remove-Item -Path $Item.FullName -Recurse -Force -ErrorAction SilentlyContinue } } } } # SIG # Begin signature block # MIIL1gYJKoZIhvcNAQcCoIILxzCCC8MCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU/eklU8qyGcYH5aJfhlHHuIMl # YLagggj8MIIDfTCCAmWgAwIBAgIQfY66zkudTZ9EnV2nSZm8oDANBgkqhkiG9w0B # AQsFADBFMRQwEgYKCZImiZPyLGQBGRYEVEVDSDEVMBMGCgmSJomT8ixkARkWBU9N # TklDMRYwFAYDVQQDEw1PTU5JQy5URUNILUNBMB4XDTE4MDMxMzIxNTY1OFoXDTIz # MDMxMzIyMDY1OFowRTEUMBIGCgmSJomT8ixkARkWBFRFQ0gxFTATBgoJkiaJk/Is # ZAEZFgVPTU5JQzEWMBQGA1UEAxMNT01OSUMuVEVDSC1DQTCCASIwDQYJKoZIhvcN # AQEBBQADggEPADCCAQoCggEBAO6V7MmlK+QuOqWIzrLbmhv9acRXB46vi4RV2xla # MTDUimrSyGtpoDQTYK2QZ3id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# MMLhc0mBwgyJVG5tiuqsVl2IEDZKuWBjjVm3/JCkDNHD5SNqs0K4+suVJwyQp5Nh # ntNC/5AqUMrVi3m8WEYeSY0Vag7fwlxLExo464bx+qiy/hBo0HsL991P09voNgrd # 7+gjlgHt4KMhMyRsKhtcveMHfXaajbJDRWw/Km1T+32tnnPt+tEJKQALsC+qNSh0 # J7NFRx3JyjL+5Tjfe+/+vYz9AI7uJdCz7w11jJV7Vcq5Zkb7tDbjvshNf4wOvXKs # CS5Vmkv5J+mnYA== # SIG # End signature block
It's a PowerShell function. You can just open PowerShell ISE as an administrator, paste the text in the window and type "Remove-OneDrive" (or "Remove-OneDrive -Offline).
I guess no, anyway seems my tool is not needed anymore, because Microsoft have added again the uninstall option for OneDrive
Godhand likes to add a signature. You could do it and so could I. All you do is add one. He thinks he is the best Powershell scripter in the world and has been moaning about how wonderful he is for months. He is better than me certainly but that isn't saying much really.