mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 22:55:52 -06:00
Rework OneDrive removal Tweak (#2155)
* Revamp Onedrive Tweak * fixes Description * Add Reg key to Cleanup and Errorhandling
This commit is contained in:
parent
2e12176b2d
commit
37b9c552df
@ -2452,31 +2452,38 @@
|
|||||||
},
|
},
|
||||||
"WPFTweaksRemoveOnedrive": {
|
"WPFTweaksRemoveOnedrive": {
|
||||||
"Content": "Remove OneDrive",
|
"Content": "Remove OneDrive",
|
||||||
"Description": "Copies OneDrive files to Default Home Folders and Uninstalls it.",
|
"Description": "Moves OneDrive files to Default Home Folders and Uninstalls it.",
|
||||||
"category": "z__Advanced Tweaks - CAUTION",
|
"category": "z__Advanced Tweaks - CAUTION",
|
||||||
"panel": "1",
|
"panel": "1",
|
||||||
"Order": "a030_",
|
"Order": "a030_",
|
||||||
"InvokeScript": [
|
"InvokeScript": [
|
||||||
"
|
"
|
||||||
|
$OneDrivePath = $($env:OneDrive)
|
||||||
Write-Host \"Kill OneDrive process\"
|
Write-Host \"Removing OneDrive\"
|
||||||
taskkill.exe /F /IM \"OneDrive.exe\"
|
$regPath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OneDriveSetup.exe\"
|
||||||
taskkill.exe /F /IM \"explorer.exe\"
|
if (Test-Path $regPath){
|
||||||
|
$OneDriveUninstallString = Get-ItemPropertyValue \"$regPath\" -Name \"UninstallString\"
|
||||||
Write-Host \"Copy all OneDrive to Root UserProfile\"
|
$OneDriveExe, $OneDriveArgs = $OneDriveUninstallString.Split(\" \")
|
||||||
Start-Process -FilePath powershell -ArgumentList \"robocopy '$($env:USERPROFILE.TrimEnd())\\OneDrive' '$($env:USERPROFILE.TrimEnd())\\' /e /xj\" -NoNewWindow -Wait
|
Start-Process -FilePath $OneDriveExe -ArgumentList \"$OneDriveArgs /silent\" -NoNewWindow -Wait
|
||||||
|
}
|
||||||
Write-Host \"Remove OneDrive\"
|
else{
|
||||||
Start-Process -FilePath winget -ArgumentList \"uninstall -e --purge --force --silent Microsoft.OneDrive \" -NoNewWindow -Wait
|
Write-Host \"Onedrive dosn't seem to be installed anymore\" -ForegroundColor Red
|
||||||
|
return
|
||||||
|
}
|
||||||
|
# Check if OneDrive got Uninstalled
|
||||||
|
if (-not (Test-Path $regPath)){
|
||||||
|
Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\"
|
||||||
|
Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait
|
||||||
|
|
||||||
Write-Host \"Removing OneDrive leftovers\"
|
Write-Host \"Removing OneDrive leftovers\"
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\Microsoft\\OneDrive\"
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\Microsoft\\OneDrive\"
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\OneDrive\"
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\OneDrive\"
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:programdata\\Microsoft OneDrive\"
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:programdata\\Microsoft OneDrive\"
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:systemdrive\\OneDriveTemp\"
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:systemdrive\\OneDriveTemp\"
|
||||||
|
reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\OneDrive\" -f
|
||||||
# check if directory is empty before removing:
|
# check if directory is empty before removing:
|
||||||
If ((Get-ChildItem \"$env:userprofile\\OneDrive\" -Recurse | Measure-Object).Count -eq 0) {
|
If ((Get-ChildItem \"$OneDrivePath\" -Recurse | Measure-Object).Count -eq 0) {
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:userprofile\\OneDrive\"
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$OneDrivePath\"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host \"Remove Onedrive from explorer sidebar\"
|
Write-Host \"Remove Onedrive from explorer sidebar\"
|
||||||
@ -2519,11 +2526,17 @@
|
|||||||
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{F42EE2D3-909F-4907-8871-4C22FC0BF756}\" -Value \"$env:userprofile\\Documents\" -Type ExpandString
|
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{F42EE2D3-909F-4907-8871-4C22FC0BF756}\" -Value \"$env:userprofile\\Documents\" -Type ExpandString
|
||||||
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{0DDD015D-B06C-45D5-8C4C-F59713854639}\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString
|
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{0DDD015D-B06C-45D5-8C4C-F59713854639}\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString
|
||||||
Write-Host \"Restarting explorer\"
|
Write-Host \"Restarting explorer\"
|
||||||
|
taskkill.exe /F /IM \"explorer.exe\"
|
||||||
Start-Process \"explorer.exe\"
|
Start-Process \"explorer.exe\"
|
||||||
|
|
||||||
Write-Host \"Waiting for explorer to complete loading\"
|
Write-Host \"Waiting for explorer to complete loading\"
|
||||||
Write-Host \"Please Note - OneDrive folder may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\"
|
Write-Host \"Please Note - The OneDrive folder at $OneDrivePath may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\"
|
||||||
|
Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow
|
||||||
Start-Sleep 5
|
Start-Sleep 5
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red
|
||||||
|
}
|
||||||
"
|
"
|
||||||
],
|
],
|
||||||
"UndoScript": [
|
"UndoScript": [
|
||||||
|
Loading…
Reference in New Issue
Block a user