kwizcom banner advertisement

SharePoint Online: PowerShell to Rename a List

Requirement: SharePoint Online PowerShell to Rename a List

How to Rename List in SharePoint Online?
To change the list name in SharePoint Online, follow these steps:
  • Navigate to your SharePoint Online list or library. Click on Settings Icon and then "List Settings" (In Classic UI, Under "List" tab, Click on "List Settings" button from the ribbon)
  • In the List settings page, Click on "List name, description and navigation" link under "General Settings" heading.
  • In General Settings page, You can update the Title of the list and click on "Save" to commit your changes.
    sharepoint online powershell rename list

PowerShell to Rename a List in SharePoint Online: 
Now lets rename a SharePoint Online list using PowerShell.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to Rename a SharePoint Online List or library using powershell
Function Rename-SPOList
{
    param
    (
        [string]$SiteURL  = $(throw "Please Enter the Site URL!"),
        [string]$ListName = $(throw "Please Enter the List Name to Renamne!"),
        [string]$NewName = $(throw "Please Enter the New Name for the List!")
    )
    Try {
        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the List
        $List=$Ctx.Web.Lists.GetByTitle($ListName) 

        $List.Title = $NewName
        $List.Update()
        $Ctx.ExecuteQuery()
            
        Write-Host "List has been Renamed to '$NewName' Successfully!" -ForegroundColor Green  
    }
    Catch {
        write-host -f Red "Error Renaming List!" $_.Exception.Message
    }
}
 
#Call the function to rename a list or library
Rename-SPOList -SiteURL "https://crescenttech.sharepoint.com/" -ListName "Documents" -NewName "Team Documents"
Please note, changing the list title doesn't change the list URL! If you need to change the URL of a SharePoint Online list, refer: How to Change the List URL in SharePoint Online using PowerShell?
SharePoint Online: PowerShell to Rename a List SharePoint Online: PowerShell to Rename a List Reviewed by Salaudeen Rajack on January 26, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.