File Share to SharePoint Online: Find Invalid Names, Paths Over 400 Characters and \\server Links Before They Break the Migration

SharePoint Online blocks the characters " * : < > ? / \ | in names, leading and trailing spaces, names like CON, PRN, AUX, NUL, COM0-9, LPT0-9, .lock and desktop.ini, anything containing _vti_ or starting with ~$, and a folder named forms at a library root. The full decoded path can be up to 400 characters, and files up to 250 GB. Scan the share for these before migrating, rename with a WhatIf pass first, then repoint \\server links inside documents to the new SharePoint URLs.

Published:

Last updated: 2026-10-29

What SharePoint Online actually rejects

RuleLimitUsually comes from
Characters " * : < > ? / \ |Not allowed in file or folder namesMac and Linux clients, NAS shares. NTFS blocks these, so a Windows share rarely has them.
Leading or trailing spacesNot allowedCopies from Macs, scripted exports, user typos
Reserved namesCON, PRN, AUX, NUL, COM0-COM9, LPT0-LPT9, .lock, desktop.iniOld DOS-era apps, Windows folder settings
Name patternsContaining _vti_, or starting with ~$FrontPage leftovers, Office owner/lock files
Folder named formsNot allowed at the root of a libraryShare folders called Forms
Full path400 characters, decoded, including the file nameDeep project trees, plus the site and library URL you add in front
File size250 GBBackups, VM images, video

# and % are allowed now. If a migration guide tells you to strip them, it's out of date; but check older apps that build URLs from file names by hand.

Two limits sit below SharePoint's. OneDrive sync puts the files under a local folder such as C:\Users\name\Contoso\Site - Documents\, and Office desktop apps can fail to open files whose local path is longer than about 260 characters. If people will sync the library, aim well under 400.

Option 1: Microsoft's free migration tools

Migration Manager (SharePoint admin center, Migration) and the SharePoint Migration Tool (SPMT) both move file shares into SharePoint for free. Both scan the source first and report items they can't move. Run the scan before the real migration and fix what it finds, because a migration that fails on 4,000 names leaves people with half a library.

  • Plan the target structure first. One share with 15 top-level folders usually becomes 15 libraries or sites, not one library with 15 folders. Every level you drop makes paths shorter.
  • Decide on permissions. NTFS permissions don't map cleanly to SharePoint. Most teams set access on the site and libraries instead of carrying every folder ACL across.
  • Exclude junk. ~$ owner files, Thumbs.db, desktop.ini and .tmp files don't need to move.
  • Run big batches outside business hours. Migrations count against the same limits as everything else; see SharePoint throttling.

Option 2: Pre-scan and rename with PowerShell

Scan the share

This lists every name SharePoint will reject, and every path that will be too long once the site and library URL are added in front. It only reads. Run it in PowerShell 7, which handles long paths on Windows.

$Source     = "\\fileserver01\Projects"
$TargetPath = "/sites/architecture-knowledge-base/Shared Documents/Projects"   # decoded, after the host name
$MaxPath    = 400

$invalidChars = '["*:<>?/\\|]'
$blockedName  = '^(CON|PRN|AUX|NUL|COM\d|LPT\d)(\..*)?$|^\.lock$|^desktop\.ini$|_vti_|^~\
    
    
    
    
    
  



$issues = foreach ($item in Get-ChildItem -LiteralPath $Source -Recurse -Force -ErrorAction SilentlyContinue) {
    $relative = $item.FullName.Substring($Source.Length).Replace("\", "/")
    $length   = ($TargetPath + $relative).Length
    $name     = $item.Name
    $problems = @()
    if ($name -match $invalidChars)  { $problems += "Invalid character" }
    if ($name -ne $name.Trim())      { $problems += "Leading or trailing space" }
    if ($name -match $blockedName)   { $problems += "Blocked name" }
    if ($length -gt $MaxPath)        { $problems += "Path over $MaxPath" }
    if (-not $item.PSIsContainer -and $item.Length -gt 250GB) { $problems += "Over 250 GB" }
    if ($problems) {
        [pscustomobject]@{
            Path         = $item.FullName
            Type         = if ($item.PSIsContainer) { "Folder" } else { "File" }
            TargetLength = $length
            Problems     = $problems -join "; "
        }
    }
}

$issues | Export-Csv .\fileshare-issues.csv -NoTypeInformation
$issues | Group-Object Problems | Sort-Object Count -Descending | Select-Object Count, Name

If you'll map a share folder to the root of a library, also flag top-level folders named forms. For long paths, the useful sort is by folder: $issues | Where-Object Problems -like "*Path over*" | Group-Object { Split-Path $_.Path -Parent } | Sort-Object Count -Descending shows which few folders cause most of the problem.

Rename what can be renamed

Invalid characters and stray spaces can be fixed automatically. The script renames the deepest items first, so renaming a folder never changes a path the loop still needs. It skips anything that would collide with an existing name, and logs every change so you can tell people where their files went. $WhatIf = $true only lists the changes.

$WhatIf = $true
$log    = @()

$toFix = Get-ChildItem -LiteralPath $Source -Recurse -Force |
    Where-Object { $_.Name -match $invalidChars -or $_.Name -ne $_.Name.Trim() } |
    Sort-Object { $_.FullName.Length } -Descending

foreach ($item in $toFix) {
    $newName = ($item.Name -replace $invalidChars, "-").Trim()
    $parent  = [IO.Path]::GetDirectoryName($item.FullName)
    if (Test-Path -LiteralPath (Join-Path $parent $newName)) {
        Write-Warning "Skipped, name already exists: $(Join-Path $parent $newName)"; continue
    }
    if ($WhatIf) { "Would rename: $($item.FullName) -> $newName" }
    else {
        Rename-Item -LiteralPath $item.FullName -NewName $newName
        $log += [pscustomobject]@{ OldPath = $item.FullName; NewName = $newName; When = Get-Date }
    }
}
if (-not $WhatIf) { $log | Export-Csv .\fileshare-renames.csv -NoTypeInformation }

Don't shorten long paths by script. Abbreviating folder names automatically produces paths nobody recognizes. Move deep branches to their own library, or drop a redundant level, such as Projects\2026\2026-014 Riverside\ becoming 2026-014 Riverside\.

Renaming files breaks links to them. That's the next problem.

Option 3: After the migration, use SharePoint Essentials Toolkit

The toolkit doesn't copy file shares; Migration Manager and SPMT do that for free. It handles the part those tools leave behind: the documents you moved are full of links that still point at the old server.

Repoint \\server links inside documents

Word, Excel and PowerPoint files, pages and list items often link to \\fileserver01\Projects\..., file://fileserver01/Projects/... or a mapped drive such as S:\Projects\.... After the move, every one of those links breaks for anyone not on the old network.

In the toolkit, open Tasks, Links, Fix or replace links in bulk, pick the sites you migrated into, then open Find & replace. Add a rule from the old share path to the new library URL:

Fix or replace links in bulk, Find and Replace: Flag only on, Contains rule with old value \\fileserver01\Projects\ and new value https://contoso.sharepoint.com/sites/architecture-knowledge-base/Shared Documents/Projects/
The old value is the file share path; the new value is the library URL. Flag only reports what would change without changing anything.

The rule also matches the file:// forms of the same path. Add one rule per share or drive letter (S:\Projects\ as well as \\fileserver01\Projects\), or use Import to load a whole mapping table from Excel:

The rule list showing rule 1: \\fileserver01\Projects\ to https://contoso.sharepoint.com/sites/architecture-knowledge-base/Shared Documents, match Contains, matched part
Rules run top to bottom, so put more specific paths above broader ones.

Run once with Flag only on and review the report. Then turn Flag only off and run again to rewrite the links. Keep Preserve Author on so Modified By doesn't become you on every file. If you renamed folders with the script above, add rules for those paths too, using fileshare-renames.csv.

The same task handles library and site renames after the move; see renaming a list or library URL.

Check path length on what landed

Run Inventory, Get inventory of item, files and page labels and metadata on the target sites and add the Item Url Path Length and Folder Depth columns. Sort descending:

Item inventory sorted by Item Url Path Length, with the longest at 386 characters at folder depth 6
Under 400, but 386 characters at depth 6 is going to fail for anyone who syncs it.

More on fixing those in SharePoint path too long.

Community Edition is free on up to 20 sites per Microsoft 365 tenant.

Frequently asked questions

What characters are not allowed in SharePoint Online file names?

The characters " * : < > ? / \ | are not allowed, nor are leading or trailing spaces. # and % are allowed. Names like CON, PRN, AUX, NUL, COM0-9, LPT0-9, .lock and desktop.ini, and names containing _vti_ or starting with ~$, are blocked.

What is the SharePoint Online path length limit?

400 characters for the full decoded path, including the site, library, folders and file name. Synced files can hit lower limits in Office desktop apps at around 260 characters of local path.

Does the SharePoint Migration Tool fix invalid file names?

Migration Manager and SPMT scan the source and report items they can't migrate. Renaming them before the migration, with a scan you control, gives you a record of what changed.

How do I fix links to \\server paths after migrating to SharePoint?

Replace the old UNC, file:// or mapped drive path with the new library URL inside documents and pages. SharePoint Essentials Toolkit does this in bulk with a Flag only preview first.

Should I migrate NTFS permissions to SharePoint?

Usually not folder by folder. Set access on sites and libraries, and use unique permissions only where needed. Folder-level ACLs carried across become hard to audit.

Fix file share links after your migration, free

SharePoint Essentials Toolkit Community Edition is free. Repoint \\server and mapped drive links in documents and pages, and check path lengths on what you moved, on up to 20 sites per Microsoft 365 tenant. Get your free Community Edition license key.

About the author. The Cognillo SharePoint Team builds and supports SharePoint Essentials Toolkit and has worked with SharePoint administrators on permissions audits, migrations and cleanup projects since 2012.