4

I have a subsite in Sharepoint Online with a web address of

https://mydomain/sites/sitecollectionName/subsite

Is it possible to change the url to

https://mydomain/sites/subsite

If I understand correctly it is possible in sharepoint 2013 using powershell Get-SPWeb and setting ServerRelativeUrl but SPO does not appear to have similar powershell commandlets

1
  • 1
    I guess you are trying change subsite to site collection, but i guess its not possible just by changing the server relative url Commented Nov 23, 2017 at 10:44

1 Answer 1

0

For SharePoint Online, we can't change the site collection URL, we can change the sub site URL using PowerShell with CSOM. The following PowerShell script for your reference:

#Configure Site URL and User
$SiteURL = "https://mydomain/sites/sitecollectionName/subsite"
$User = "[email protected]"
$Password = "Password"
$newUrl= "/sites/sitecollectionName/mysubsite"


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"

$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$SecurePassword)

$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$context.Credentials = $creds
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()

$web.ServerRelativeUrl = $newUrl
$web.update()
$context.ExecuteQuery()

How to change the Subsite URL property using PowerShell in SharePoint Online

3
  • 1
    Here in question looks like he is trying to convert subsite to a site another collection. Does this server-relative URL change work for this? I guess its only for changing subsite URL respective to its site collection URL not to another site collection. Commented Nov 23, 2017 at 9:22
  • 2
    The suggested script works only if I keep the sitecollection path as part of the new url mydomain/sites/sitecollectionName/newsubsite I want to change url to mydomain/sites/subsite effectively removing the reference to SiteCollection in the path I get an exception "Invalid URL" when I run the script So looks like not possible Commented Nov 23, 2017 at 10:27
  • 1
    Yes, the script work for change the sub site url, not change site collection url.
    – LZ_MSFT
    Commented Nov 24, 2017 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.