working with invalid name in SharePoint online

Carl94580345 31 Reputation points
2024-04-15T19:02:49.42+00:00

Working with invalid name in SharePoint online, after content was migrated with mover.io. Looking for the best way to find invalid names and rename them.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,658 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 16,091 Reputation points Microsoft Vendor
    2024-04-16T02:50:50.4733333+00:00

    Hi @Carl94580345,

    To find and rename invalid names in SharePoint Online, you can use PowerShell.Here's an example PowerShell script that renames all items with invalid names in a SharePoint Online site:

    # Connect to SharePoint Online
    Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite
    
    # Get all list items
    $items = Get-PnPListItem -List "Your List Name"
    
    # Define regular expression to match invalid characters
    $regex = '[\\\/\:\*\?\"\<\>\|\#]'
    
    # Loop through each item and rename if necessary
    foreach ($item in $items) {
        if ($item.FieldValues.FileLeafRef -match $regex) {
            $newName = $item.FieldValues.FileLeafRef -replace $regex, ""
            Set-PnPListItem -List "Your List Name" -Identity $item.Id -Values @{FileLeafRef=$newName}
        }
    }
    

    Replace "Your List Name" with the name of the list or library you want to rename items in. You may also need to modify the regular expression to match the specific invalid characters in your environment.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.