-
Notifications
You must be signed in to change notification settings - Fork 16
/
FileShareToSPO_Migration_Check.ps1
85 lines (68 loc) · 2.37 KB
/
FileShareToSPO_Migration_Check.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
<#
===========================================================================
Created on: 10/08/2020 10:02
Created by: Ben Whitmore
Filename: Path_Length.ps1
===========================================================================
Version:
1.0
.SYNOPSIS
This script is designed to highlight files on a fileshare that will not be able to be
moved to SharePoint online using the SharePoint Migration Tool
.Parameter Path
File Path to test
.Parameter Length
Length of path to test. SharePoint online has a 400 character limit for a file path
https://support.microsoft.com/en-gb/office/invalid-file-names-and-file-types-in-onedrive-
and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa?ui=en-us&rs=en-
gb&ad=gb#invalidfilefoldernames
.Parameter OutDir
Specify target Out Directory
.Example
Path_Length.ps1 -Path "D:\Test\Files" -Length "400" -OutDir "C:\Outs"
#>
Param
(
[Parameter(Mandatory = $True)]
[String]$Path,
[Parameter(Mandatory = $False)]
[String]$Length = 400,
[String]$OutDir
)
$ScriptPath = $MyInvocation.MyCommand.Path
$CurrentDir = Split-Path $ScriptPath
#Reset Warning
$WarningPath = $Null
#Specify Out File
$OutFile = "SPO_Migrate_Out.csv"
If ($OutDir) {
$OutDir = $OutDir
}
Else {
$OutDir = $CurrentDir
}
#Get file info from fileshare
Try {
$Files = Get-ChildItem -Path $Path -recurse -ErrorAction Continue -ErrorVariable Error_GCI | Select-Object Name, Fullname
}
Catch {
Write-Warning "Path error: $($Path), Error: $($Error_GCI)"
$WarningPath = $True
}
#Write-Warning "File path is greater than $($Length) characters for the following files"
ForEach ($File in $Files) {
If ($File.FullName.Length -gt $Length) {
$WarningPath = $True
}
}
#Show error if files with large paths found
If ($WarningPath -eq $True) {
Write-Warning "Some files in path ""$($Path)"" exceeded the path length of $($Length) or the path was unreadable. See the Out-GridView for more information"
$WarningPath = $Null
}
#Save Out to Path being checked
$Files | Select-Object Fullname, @{Name = "Path_Length"; Expression = { $_.FullName.Length } } | Sort-Object Path_Length -Descending | Export-Csv (Join-Path $OutDir "SPO_Migration_Check.csv") -Append
#Output results to Grid View
$Files | Select-Object Fullname, @{Name = "Path_Length"; Expression = { $_.FullName.Length
}
} | Sort-Object Path_Length -Descending | Out-GridView