Search code examples
azurepowershellmicrosoft-graph-apisharepoint-onlinesharepoint-rest-api

Rename SharePoint site with Graph API or REST


I am looking for the ability to programmability change the name of a sharepoint site with either Graph API or SharePoint REST (or related powershell modules)

I have tried "Set-PnPWeb" this command seems to change the site title then revert back after a bit.

In the screen shot I want to change "Site Name" (also whats the difference between "Name" and "Site Name"?)


Solution

  • whats the difference between "Name" and "Site Name"?

    Whenever you create team site in SharePoint, Microsoft 365 group will also be created automatically with same name as site. Here, Name refers to Microsoft 365 group name whereas Site Name refers to SharePoint site name.

    I have one SharePoint team site named demoteamsite12 with below properties:

    enter image description here

    In my case, I ran below PowerShell commands to change site name and got response like this:

    $oldSiteURL = "‎https://xxxxxx.sharepoint.com/sites/‎‎demoteamsite12"
    
    Connect-PnPOnline -Url $oldSiteURL -Interactive
    
    $newSiteName = "teamsite12"
    $newSiteUrl = "https://xxxxxxxx.sharepoint.com/sites/teamsite12"
    
    Rename-PnPTenantSite -Identity $oldSiteUrl -NewSiteUrl $newSiteUrl -NewSiteTitle $newSiteName -Wait
    

    Response:

    enter image description here

    When you check the site properties in SharePoint Admin Portal now, only site name and site address will be changed as below:

    enter image description here

    Alternatively, you can also below PowerShell script to achieve the same if above does not work:

    Install-Module Microsoft.Online.SharePoint.PowerShell -force
    
    # Connect to SharePoint Online
    Connect-SPOService -Url https://xxxxxxxxx-admin.sharepoint.com
    
    # Define the old site URL and the new site URL
    $oldSiteUrl = "https://xxxxxxxxx.sharepoint.com/sites/teamsite12"
    $newSiteUrl = "https://xxxxxxxxx.sharepoint.com/sites/demosite12"
    
    # Define the new site title
    $newSiteName = "demosite12"
    
    # Start the site rename operation
    Start-SPOSiteRename -Identity $oldSiteUrl -NewSiteUrl $newSiteUrl -NewSiteTitle $newSiteName
    

    Response:

    enter image description here

    When I checked the same in SharePoint Admin Portal after few minutes, site name changed successfully as below:

    enter image description here

    Reference:

    Start-SPOSiteRename (Microsoft.Online.SharePoint.PowerShell) | Microsoft