|
2682 | 2682 | "
|
2683 | 2683 | $OneDrivePath = $($env:OneDrive)
|
2684 | 2684 | Write-Host \"Removing OneDrive\"
|
| 2685 | + |
| 2686 | + # Check both traditional and Microsoft Store installations |
2685 | 2687 | $regPath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OneDriveSetup.exe\"
|
| 2688 | + $msStorePath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Appx\\AppxAllUserStore\\Applications\\*OneDrive*\" |
| 2689 | + |
2686 | 2690 | if (Test-Path $regPath) {
|
2687 | 2691 | $OneDriveUninstallString = Get-ItemPropertyValue \"$regPath\" -Name \"UninstallString\"
|
2688 | 2692 | $OneDriveExe, $OneDriveArgs = $OneDriveUninstallString.Split(\" \")
|
2689 | 2693 | Start-Process -FilePath $OneDriveExe -ArgumentList \"$OneDriveArgs /silent\" -NoNewWindow -Wait
|
| 2694 | + } elseif (Test-Path $msStorePath) { |
| 2695 | + Write-Host \"OneDrive appears to be installed via Microsoft Store\" -ForegroundColor Yellow |
| 2696 | + # Attempt to uninstall via winget |
| 2697 | + Start-Process -FilePath winget -ArgumentList \"uninstall -e --purge --accept-source-agreements Microsoft.OneDrive\" -NoNewWindow -Wait |
2690 | 2698 | } else {
|
2691 |
| - Write-Host \"Onedrive dosn't seem to be installed anymore\" -ForegroundColor Red |
2692 |
| - return |
| 2699 | + Write-Host \"OneDrive doesn't seem to be installed\" -ForegroundColor Red |
| 2700 | + Write-Host \"Running cleanup if OneDrive path exists\" -ForegroundColor Red |
2693 | 2701 | }
|
2694 |
| - # Check if OneDrive got Uninstalled |
2695 |
| - if (-not (Test-Path $regPath)) { |
| 2702 | + |
| 2703 | + # Check if OneDrive got Uninstalled (both paths) |
| 2704 | + if (Test-Path $OneDrivePath) { |
2696 | 2705 | Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\"
|
2697 | 2706 | Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait
|
2698 | 2707 |
|
|
2758 | 2767 | Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow
|
2759 | 2768 | Start-Sleep 5
|
2760 | 2769 | } else {
|
2761 |
| - Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red |
| 2770 | + Write-Host \"Nothing to Cleanup with OneDrive\" -ForegroundColor Red |
2762 | 2771 | }
|
2763 | 2772 | "
|
2764 | 2773 | ],
|
|
0 commit comments