Advertisement
Guest User

ODFBFuckup

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##ODFB Cleanup
  2. $OD = "C:\Users\$env:username\OneDrive for Business"
  3. $ODBA = "C:\Users\$env:username\OneDrive for Business - Unsynced Changes"
  4. $ODBB = "C:\users\$env:username\OneDriveBackup"
  5. $FolderList = @()
  6.  
  7. ####
  8. #Stop OneDrive For Business and the Upload Center. Confirm they are stopped.
  9. Write-Host -ForegroundColor Green "Stopping Groove.exe and MSOSync.exe"
  10. Get-Process -Name groove,msosync -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited} | Stop-Process -Verbose
  11. Start-Sleep -Seconds 5
  12. if (Get-Process groove,msosync -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited})
  13. {
  14.     Write-Host -ForegroundColor Red "One or both process are still running. Manually verify/stop and then run script again."
  15.     Return
  16. }
  17. else
  18. {
  19.     Write-Host -ForegroundColor Green "Stopped Groove.exe and MSOSync.exe"
  20.     Write-Host ''
  21. }
  22. Start-Sleep -Seconds 3
  23. ####
  24. #Create backup directory. Confirm OneDrive For Business folders and move them into backup directory. If ODFB folders cannot be confirmed, request folder names
  25. Write-Host -ForegroundColor Green "Creating backup directory if it does not exist"
  26. if (!(test-path "C:\users\$env:username\OneDriveBackup"))
  27. {
  28.     New-Item -ItemType Directory -Name "OneDriveBackup" -Path "C:\users\$env:username\"  -Verbose | Out-Null
  29.     Write-Host ''
  30. }
  31. Start-Sleep -Seconds 3
  32. ####
  33. #Read a list of folders to be moved into OneDriveBackup
  34. Write-Host ''
  35. Write-Host -ForegroundColor Green "Below is a list of folders in C:\users\$env:username"
  36. Get-ChildItem -Path C:\users\$env:username | select -exp Name | Format-List
  37. Write-Host ''
  38. Write-Host -ForegroundColor Green "Enter the names of the folders to be moved into backup, separated by a comma"
  39. Write-Host -ForegroundColor Green "Example: OneDrive For Business, OneDrive For Business - Unsynced Changes"
  40. [array]$FolderList = (Read-Host “Folder Names”).split(,) | %{$_.trim()}
  41.  
  42. #Test path of each folder, then move the folder into OneDriveBackup
  43. foreach ($Folder in $FolderList)
  44. {
  45.     if (!(test-path "C:\users\$env:username\$Folder"))
  46.     {
  47.         Write-Host -ForegroundColor Red "$Folder could not be found, please check your spelling and re-run the script"
  48.         Return
  49.     }
  50. }
  51. foreach ($Folder in $FolderList)
  52. {
  53.     $Source = "C:\Users\$env:username\$Folder"
  54.     Write-Host -ForegroundColor Green "Moving $folder into OneDriveBackup..."
  55.     Write-Host "/C MOVE $source $ODBB"
  56.     CMD /C MOVE $source $ODBB
  57. }
  58. Start-Sleep -Seconds 3
  59. ###
  60. #Test the path of the two ODFB cache folders, then delete
  61. $FileCache1 = "C:\users\$env:username\AppData\Local\Microsoft\Office\15.0"
  62. $FileCache2 = "C:\users\$env:username\AppData\Local\Microsoft\Office\SPW"
  63. if (Test-Path $FileCache1)
  64. {
  65.     Write-Host ''
  66.     Write-Host -ForegroundColor Green "Deleting the 15.0 Cache Folders"
  67.     Write-Host -ForegroundColor Yellow "OfficeFileCache"
  68.     CMD /C RMDIR /S /Q "$FileCache1\OfficeFileCache"
  69.     Write-Host -ForegroundColor Yellow "WebServiceCache"
  70.     CMD /C RMDIR /S /Q "$FileCache1\WebFileCache"
  71.     Write-Host -ForegroundColor Yellow "WEF"
  72.     CMD /C RMDIR /S /Q "$FileCache1\WEF"
  73. }
  74. else{Write-Host -ForegroundColor Red "Something is wrong with the path: $FileCache1";Return}
  75.  
  76. if (Test-Path $FileCache2)
  77. {
  78.     Write-Host ''
  79.     Write-Host -ForegroundColor Green "Deleting the SPW Folder"
  80.     Write-Host "CMD /C RMDIR /S /Q $FileCache2"
  81.     CMD /C RMDIR /S /Q $FileCache2
  82.     Write-Host -ForegroundColor Green '####'
  83.     Write-Host -ForegroundColor Green 'DONE'
  84.     Write-Host -ForegroundColor Green '####'
  85. }
  86. else{Write-Host -ForegroundColor Red "Something is wrong with the path: $FileCache1";Return}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement