项目作者: jaka

项目描述 :
Disable Onedrive with Powershell
高级语言:
项目地址: git://github.com/jaka/windows10-disable-onedrive.git
创建时间: 2019-02-14T15:57:58Z
项目社区:https://github.com/jaka/windows10-disable-onedrive

开源协议:

下载


Disable One Drive in Windows 10

Run with administrator privileges

  1. Function Force-New-Item([String]$Path)
  2. {
  3. If (!(Test-Path $Path)) {
  4. New-Item -Force -Path $Path
  5. }
  6. }
  7. Function RemoveAcl([String]$File)
  8. {
  9. If (!(Test-Path -Path "$File")) {
  10. Return
  11. }
  12. $Acl = Get-Acl $File
  13. $Acl.SetAccessRuleProtection($true, $true)
  14. Set-Acl -Path $File -AclObject $Acl
  15. $Acl = Get-Acl $File
  16. $Acl.Access | Where-Object { $_.IdentityReference -NotMatch "APPLICATION PACKAGE AUTHORITY" } | ForEach {
  17. $Acl.RemoveAccessRule($_)
  18. }
  19. Set-Acl -Path $File -AclObject $Acl
  20. }
  21. Function DisableOneDrive
  22. {
  23. Stop-Process -Name "OneDrive" -Force -ErrorAction SilentlyContinue
  24. Stop-Process -Name "OneDriveSetup" -Force -ErrorAction SilentlyContinue
  25. $Paths = @("$env:SYSTEMROOT\System32", "$env:SYSTEMROOT\SysWOW64")
  26. ForEach ($Path in $Paths) {
  27. $OneDriveSetup = Join-Path -Path $Path -ChildPath "OneDriveSetup.exe"
  28. if (Test-Path -Path "$OneDriveSetup" -PathType Leaf) {
  29. Start-Process "$OneDriveSetup" "/uninstall" -NoNewWindow -Wait
  30. Start-Sleep -s 3
  31. RemoveAcl "$OneDriveSetup"
  32. }
  33. }
  34. Stop-Process -Name "explorer" -Force -ErrorAction SilentlyContinue
  35. Start-Sleep -s 2
  36. # Remove OneDrive from File Explorer
  37. $OneDrive = "HKLM:SOFTWARE\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
  38. Force-New-Item -Path "$OneDrive"
  39. Set-ItemProperty -Path "$OneDrive" -Name "System.IsPinnedToNameSpaceTree" -Type DWORD -Value 0
  40. $OneDrive = "HKLM:SOFTWARE\Classes\CLSID\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}"
  41. Force-New-Item -Path "$OneDrive"
  42. Set-ItemProperty -Path "$OneDrive" -Name "System.IsPinnedToNameSpaceTree" -Type DWORD -Value 0
  43. REG LOAD HKU\Default C:\Users\Default\NTUSER.DAT
  44. Remove-ItemProperty -Path "Registry::HKU\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup"
  45. REG UNLOAD HKU\Default
  46. $Roots = @("HKLM:\SOFTWARE", "HKLM:\SOFTWARE\Wow6432Node")
  47. $SubRoot = "Policies\Microsoft\Windows\OneDrive"
  48. $NameSpaces = Join-Path -Path $Roots -ChildPath $SubRoot
  49. ForEach ($OneDrive in $NameSpaces) {
  50. Force-New-Item -Path $OneDrive
  51. # Prevent the usage of OneDrive for file storage
  52. Set-ItemProperty -Path $OneDrive -Name "DisableFileSync" -Type DWORD -Force -Value 1
  53. # Prevent the usage of OneDrive for file storage
  54. Set-ItemProperty -Path $OneDrive -Name "DisableFileSyncNGSC" -Type DWORD -Force -Value 1
  55. # Save documents to OneDrive by default
  56. Set-ItemProperty -Path $OneDrive -Name "DisableLibrariesDefaultSaveToOneDrive" -Type DWORD -Force -Value 0
  57. }
  58. Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\OneDrive" -Recurse -Force -ErrorAction SilentlyContinue
  59. Remove-Item -Path "$env:PROGRAMDATA\Microsoft OneDrive" -Recurse -Force -ErrorAction SilentlyContinue
  60. Remove-Item -Path "$env:SYSTEMDRIVE\OneDriveTemp" -Recurse -Force -ErrorAction SilentlyContinue
  61. $CommonApplicationData = [Environment]::GetFolderPath("CommonApplicationData")
  62. $Path = Join-Path -Path "$CommonApplicationData" -ChildPath "Microsoft OneDrive"
  63. Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path $Path
  64. }
  65. DisableOneDrive