Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##ODFB Cleanup
- $OD = "C:\Users\$env:username\OneDrive for Business"
- $ODBA = "C:\Users\$env:username\OneDrive for Business - Unsynced Changes"
- $ODBB = "C:\users\$env:username\OneDriveBackup"
- $FolderList = @()
- ####
- #Stop OneDrive For Business and the Upload Center. Confirm they are stopped.
- Write-Host -ForegroundColor Green "Stopping Groove.exe and MSOSync.exe"
- Get-Process -Name groove,msosync -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited} | Stop-Process -Verbose
- Start-Sleep -Seconds 5
- if (Get-Process groove,msosync -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited})
- {
- Write-Host -ForegroundColor Red "One or both process are still running. Manually verify/stop and then run script again."
- Return
- }
- else
- {
- Write-Host -ForegroundColor Green "Stopped Groove.exe and MSOSync.exe"
- Write-Host ''
- }
- Start-Sleep -Seconds 3
- ####
- #Create backup directory. Confirm OneDrive For Business folders and move them into backup directory. If ODFB folders cannot be confirmed, request folder names
- Write-Host -ForegroundColor Green "Creating backup directory if it does not exist"
- if (!(test-path "C:\users\$env:username\OneDriveBackup"))
- {
- New-Item -ItemType Directory -Name "OneDriveBackup" -Path "C:\users\$env:username\" -Verbose | Out-Null
- Write-Host ''
- }
- Start-Sleep -Seconds 3
- ####
- #Read a list of folders to be moved into OneDriveBackup
- Write-Host ''
- Write-Host -ForegroundColor Green "Below is a list of folders in C:\users\$env:username"
- Get-ChildItem -Path C:\users\$env:username | select -exp Name | Format-List
- Write-Host ''
- Write-Host -ForegroundColor Green "Enter the names of the folders to be moved into backup, separated by a comma"
- Write-Host -ForegroundColor Green "Example: OneDrive For Business, OneDrive For Business - Unsynced Changes"
- [array]$FolderList = (Read-Host “Folder Names”).split(“,”) | %{$_.trim()}
- #Test path of each folder, then move the folder into OneDriveBackup
- foreach ($Folder in $FolderList)
- {
- if (!(test-path "C:\users\$env:username\$Folder"))
- {
- Write-Host -ForegroundColor Red "$Folder could not be found, please check your spelling and re-run the script"
- Return
- }
- }
- foreach ($Folder in $FolderList)
- {
- $Source = "C:\Users\$env:username\$Folder"
- Write-Host -ForegroundColor Green "Moving $folder into OneDriveBackup..."
- Write-Host "/C MOVE $source $ODBB"
- CMD /C MOVE $source $ODBB
- }
- Start-Sleep -Seconds 3
- ###
- #Test the path of the two ODFB cache folders, then delete
- $FileCache1 = "C:\users\$env:username\AppData\Local\Microsoft\Office\15.0"
- $FileCache2 = "C:\users\$env:username\AppData\Local\Microsoft\Office\SPW"
- if (Test-Path $FileCache1)
- {
- Write-Host ''
- Write-Host -ForegroundColor Green "Deleting the 15.0 Cache Folders"
- Write-Host -ForegroundColor Yellow "OfficeFileCache"
- CMD /C RMDIR /S /Q "$FileCache1\OfficeFileCache"
- Write-Host -ForegroundColor Yellow "WebServiceCache"
- CMD /C RMDIR /S /Q "$FileCache1\WebFileCache"
- Write-Host -ForegroundColor Yellow "WEF"
- CMD /C RMDIR /S /Q "$FileCache1\WEF"
- }
- else{Write-Host -ForegroundColor Red "Something is wrong with the path: $FileCache1";Return}
- if (Test-Path $FileCache2)
- {
- Write-Host ''
- Write-Host -ForegroundColor Green "Deleting the SPW Folder"
- Write-Host "CMD /C RMDIR /S /Q $FileCache2"
- CMD /C RMDIR /S /Q $FileCache2
- Write-Host -ForegroundColor Green '####'
- Write-Host -ForegroundColor Green 'DONE'
- Write-Host -ForegroundColor Green '####'
- }
- else{Write-Host -ForegroundColor Red "Something is wrong with the path: $FileCache1";Return}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement