-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Enable-PersonalOneDrive.ps1
89 lines (79 loc) · 1.85 KB
/
Enable-PersonalOneDrive.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<#
Computer\HKEY_CURRENT_USER\Software\Policies\Microsoft\OneDrive
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager
#>
# check is personal account is available
Begin
{
function GetSyncRootPath ($parentName)
{
$key = Get-Item "$name\UserSyncRoots"
if ($key)
{
$parts = $name.Split('!')
if ($parts.Count -gt 1)
{
$path = $key.GetValue($parts[1], $null)
return $path
}
}
return $null
}
}
Process
{
$foundBusiness = $false
$foundPersonal = $false
$0 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager'
Get-ChildItem $0 | % { $_.Name.Replace('HKEY_LOCAL_MACHINE', 'HKLM:') } | % `
{
$name = $_
if ($name -match 'Personal')
{
$path = GetSyncRootPath($name)
if ($path)
{
Write-Host "... found Personal folder $path"
$foundPersonal = $true
}
}
elseif ($name -match 'Business')
{
$path = GetSyncRootPath($name)
if ($path)
{
Write-Host "... found Business folder $path"
$foundBusiness = $true
}
}
}
if (-not $foundPersonal)
{
Write-Host '... did not find personal account' -ForegroundColor Yellow
Write-Host '... Right-click OneDrive tray icon and add account' -ForegroundColor DarkYellow
return
}
if (-not $foundBusiness)
{
Write-Host '... did not find business account; nothing further to do'
return
}
# check if personal sync is enabled
$0 = 'HKCU:\Software\Policies\Microsoft\OneDrive';
$key = Get-Item $0
$disabled = $key.GetValue('DisablePersonalSync', $null)
if ($disabled -eq $null)
{
Write-Host '... OneDrive key not found in Registry. Is OneDrive installed?' -ForegroundColor Yellow
return
}
elseif ($disabled -ne 0)
{
Write-Host '... enabling personal sync'
Set-ItemProperty $0 -Name 'DisablePersonalSync' -value 0 -Type Dword
}
else
{
Write-Host '... personal sync is enabled'
}
}