How can I find subfolders with over 50k items for a SharePoint migration?

0
5
Asked By CuriousCat42 On

I'm in the process of migrating a large file share to SharePoint Online, which has a limit of 50k files in any folder, including its subfolders. During my testing, several top-level folders exceeded this threshold, leading to errors. I need to create a PowerShell script that identifies all subfolders containing more than 50k items in their subfolders. For instance, if 'G:hrhiringJan1-7' has over 50k items combined in its subdirectories, I want to report that along with counts for upper levels like 'G:hrhiring' or 'G:hr'. I'm looking for guidance on how to script this efficiently without listing all subfolders individually, as there are around 24k subfolders in total.

5 Answers

Answered By OldSchoolCoder On

If you're looking for accuracy and speed, I recommend utilizing PowerShell to iterate through directories but doing it on the server. One example could be:

```powershell
Get-ChildItem "F:" -Recurse -Directory | ForEach-Object {
$folder = $_.FullName
$count = (Get-ChildItem -Path $folder -Recurse).Count
if ($count -gt 50000) {
[PSCustomObject]@{ Path = $folder; ItemCount = $count }
}
}
```
This will output the paths for those larger directories efficiently.

Answered By PowershellBotanist On

Running a count on the directory can be tricky with large folders. I'd recommend using `System.IO.Directory` methods directly. You could try this code to list out the counts by level:

```powershell
function Measure-FileCount {
param(
[Parameter(ValueFromPipeline, Mandatory)]
[System.IO.DirectoryInfo]$Path
)
process {
$childCount = ($Path.GetDirectories() | Measure-FileCount).FileCount
$count = $Path.GetFiles().Count
[pscustomobject]@{
Path = $Path.FullName
FileCount = $count
TotalCount = $count + $childCount
}
}
}

Measure-FileCount 'G:' | Where-Object { $_.TotalCount -gt 50000 } | Format-Table
```
This gives you a concise list of folders and can help you determine where you'll need to make adjustments for the migration.

DataGuru99 -

This method sounds a lot more efficient! I think using a custom object like you've shown will definitely help structure the results better.

Answered By StorageSensei On

I feel your pain about file limits! Instead of just PowerShell, using tools like WizTree can quickly analyze folder sizes and report on the item counts. It's not PowerShell, but if you script it to call WizTree, you can grab the CSV output and sort it by item count.

Answered By ScriptSavant92 On

I hear you on dealing with many files! For your task, I suggest using `Get-ChildItem` with the `-Recurse` flag to count all the items inside. You can loop through each subfolder and check if the count exceeds 50k. If it does, log that folder. For better performance, consider calling .NET methods directly instead of `Get-ChildItem`, as it's faster. Here's a snippet you could start with:

```powershell
$folders = Get-ChildItem 'G:HR' -Directory -Recurse |
Where-Object {($_ | Get-ChildItem -Recurse).Count -gt 50000}
$folders | ForEach-Object {"$($_.FullName) - $($_.Count)"}
```
Give this a try and see if it works!

TechWiz12 -

That script approach seems solid. Just make sure you're running it on your local server for quicker results. Sorting through large data sets can be taxing on resources.

Answered By SpeedyTechie On

You mentioned 24k subfolders; that's a lot! I suggest a recursive approach for simplicity:

```powershell
function Get-HeavyFolders {
param([string]$root)
$folders = Get-ChildItem -Path $root -Directory -Recurse
foreach ($folder in $folders) {
$count = (Get-ChildItem -Path $folder.FullName -Recurse | Measure-Object).Count
if ($count -gt 50000) {
"$($folder.FullName) - $count items"
}
}
}

Get-HeavyFolders 'G:HR'
```
This should help you identify which folders to focus on!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.