-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSharepoint-Duplicates.ps1
More file actions
52 lines (41 loc) · 1.57 KB
/
Sharepoint-Duplicates.ps1
File metadata and controls
52 lines (41 loc) · 1.57 KB
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
# Sort of works.
# Searches through a DML for possible duplicates with the methodology that it will likely say -LT01 or -DT01 so it's looking for "-" and then a name.
#
# Requires:
# PowerShell 7
# AAD Connected device
# Cross tenant connection is not allowed
#
# WRitten by Jonathan Bullock
# 2024 - 11 - 21
# add variables
$siteUrl = "https://YourTenantName.sharepoint.com/sites/YourSiteName"
$libraryName = "Documents" # Replace with your DL name
# Connect to SharePoint Online
Connect-PnPOnline -Url $siteUrl -UseWebLogin
# Get all items from the document library
$items = Get-PnPListItem -List $libraryName -PageSize 500 -Fields FileLeafRef, FileDirRef
# Create array to store possible duplicates
$potentialDuplicates = @()
# Check for duplicate patterns in file/folder names
foreach ($item in $items) {
$fileName = $item["FileLeafRef"]
$filePath = $item["FileDirRef"]
# Check for computer name pattern in the file/folder name (e.g., "-PCName" or "-Laptop") Hopefully works?
if ($fileName -match "-\w+$") {
$potentialDuplicates += [PSCustomObject]@{
Name = $fileName
Path = $filePath
FullPath = "$filePath/$fileName"
}
}
}
# Output potential duplicates
if ($potentialDuplicates.Count -gt 0) {
Write-Host "Potential duplicates found:" -ForegroundColor Green
$potentialDuplicates | Format-Table -AutoSize
} else {
Write-Host "No potential duplicates found." -ForegroundColor Yellow
}
# Optionally export to a CSV
$potentialDuplicates | Export-Csv -Path "PotentialDuplicates.csv" -NoTypeInformation