Browse Source

remove additional files inside Windows\WinSxS when removing onedrive

pull/41/head
Alex Hirsch 9 years ago
parent
commit
47c2666ddd
  1. 26
      lib/take-own.psm1
  2. 11
      scripts/remove-onedrive.ps1

26
lib/take-own.psm1

@ -32,6 +32,32 @@ function Takeown-Registry($key) {
$key.SetAccessControl($acl) $key.SetAccessControl($acl)
} }
function Takeown-File($path) {
takeown.exe /A /F $path
$acl = Get-Acl $path
# get administraor group
$admins = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$admins = $admins.Translate([System.Security.Principal.NTAccount])
# add NT Authority\SYSTEM
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($admins, "FullControl", "None", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl -Path $path -AclObject $acl
}
function Takeown-Folder($path) {
Takeown-File $path
foreach ($item in Get-ChildItem $path) {
if (Test-Path $item -PathType Container) {
Takeown-Folder $item.FullName
} else {
Takeown-File $item.FullName
}
}
}
function Elevate-Privileges { function Elevate-Privileges {
param($Privilege) param($Privilege)
$Definition = @" $Definition = @"

11
scripts/remove-onedrive.ps1

@ -1,6 +1,8 @@
# Description: # Description:
# This script will remove and disable OneDrive integration. # This script will remove and disable OneDrive integration.
Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1
echo "Kill OneDrive process" echo "Kill OneDrive process"
taskkill.exe /F /IM "OneDrive.exe" taskkill.exe /F /IM "OneDrive.exe"
taskkill.exe /F /IM "explorer.exe" taskkill.exe /F /IM "explorer.exe"
@ -36,3 +38,12 @@ rm -Force -ErrorAction SilentlyContinue "$env:userprofile\AppData\Roaming\Micros
echo "Restarting explorer" echo "Restarting explorer"
start "explorer.exe" start "explorer.exe"
echo "Waiting for explorer to complete loading"
sleep 10
echo "Removing additional OneDrive leftovers"
foreach ($item in (ls "$env:WinDir\WinSxS\*onedrive*")) {
Takeown-Folder $item.FullName
rm -Recurse -Force $item.FullName
}

Loading…
Cancel
Save