Solve sync issue in OneDrive for Business

Recently, I start using the tools that are included into Office 365, especially OneDrive for Business. If the installation and configuration is pretty straight forward, the sync didn’t go smooth at all. It looks like there is a lot of restriction that the client doesn’t handle properly. As a result, the sync get stuck with various error and no luck to fix them. After few reinstall I made a Powershell script that is checking before the sync that all your folders respects the requirements.

This is the requirement that I have found so far. If you find other ones, fill free to comment this post:

  • The absolute path of your folders should not exeeds 250 charactere
  • The absolute path of your files should not exeeds 256 charactere
  • The names of your files should not exeeds 256 charactere
  • You should have less that 20000 items to sync
  • The following charactere are not supported:
    • %
    • #
    • &
    • ~
  • The extension json can’t be sync

I guess this list isn’t complete since some of my file have been refuse by OneDrive due to an unjustified lack of space error, since I had 500GB remaining.
Here is a Powershell script that allow to display the items in your folder that doesn’t match those rules:

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
$MyDir = "$env:USERPROFILE\OneDrive for Business"
 
# Check Folder Path < 250
$folders = cmd /c dir $MyDir /s /-c /a:h /a:d
$folders = $folders -match "Directory"
$folders = $folders | %{$_.Replace(" Directory of ","")}
$rc =0
foreach ($folder in $folders) {
	if ($folder.length -gt 250) {
		$rc = 1
		write-host $folder
	}
}
if ($rc -eq 0) {
	Write-Host "All your folders have a Path < 250. Passed"
}
 
# Check File FullPath < 256
$files = Get-ChildItem $MyDir -rec | Where-Object {$_.FullName.Length -gt 256}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "All your files have a FullPath < 256. Passed"
}
 
# Check File name < 256
$files = Get-ChildItem $MyDir -rec | Where-Object {$_.Name.Length -gt 256}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "All your files have a Name < 256. Passed"
}
 
# Check less than 20 000 items
$Num = (Get-ChildItem $MyDir -Recurse -force | Measure-Object).Count
if ($Num -gt 20000) {
	Write-Host $Num
} else {
	Write-Host "You have less than 20000 items ($Num). Passed"
}
 
# Check for illegal character
$files = gci $MyDir -rec | ? {-not $_.psicontainer -and $_.name.Contains("%")}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "None of your files contains %. Passed"
}
# Check for illegal character
$files = gci $MyDir -rec | ? {-not $_.psicontainer -and $_.name.Contains("`#")}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "None of your files contains #. Passed"
}
# Check for illegal character
$files = gci $MyDir -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "None of your files contains &. Passed"
}
 
# Check for illegal character
$files = gci $MyDir -rec | ? {-not $_.psicontainer -and $_.name.Contains("~")}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "None of your files contains ~. Passed"
}
 
# Check for illegal extension
$files = gci $MyDir -rec | ? {-not $_.psicontainer -and $_.name.Contains(".json")}
if ($files.Count -ne 0) {
	$files
} else {
	Write-Host "None of your files is a json. Passed"
}

Leave a Reply

Your email address will not be published. Required fields are marked *