SharePoint Online: Change List URL using PowerShell
Save this file as .ps1 extension and execute in powershell/SharePoint Online Powershell
------------------------------------------------------------------------------------
#Web url where is the list exist, of which we need to change the URL
$url = "https://test.sharepoint.com/sites/sample/"
$userName ="Your sie User Name" # Your site user name
$password ="Password" # Password
# convert password into secured string
$securedpw = ConvertTo-SecureString $password -AsPlainText -Force
#Creating instance of client context
[Microsoft.SharePoint.Client.ClientContext]$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securedpw)
#Fetching the list
$web = $clientContext.Web
$lists = $web.Lists
$clientContext.Load($web)
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
$list =$lists.GetByTitle("Project Documents") # TestList is also the title of list which we want to change
$clientContext.Load($list)
$clientContext.ExecuteQuery()
#Fetching the RootFolder of the list
$rootfolder = $list.RootFolder
#Move the root folder to new URL
$rootfolder.MoveTo("https://test.sharepoint.com/sites/sample/Lists/ProjectDoc/") # NewURL - new url of the list
$clientContext.ExecuteQuery()
Comments
Post a Comment