SOLVED

Change a Modern SharePoint subsite to its own site

Brass Contributor

I have a modern SharePoint site that I am using as a 'template'. 

What I am actually doing is copying the content from the parent site to a subsite.

 

What I end up with is a URL looking like this: https://admin.sharepoint.com/sites/MyTemplateSite/CreatedSubSite

 

I want to know if I can take the subsite and make it independent of the parent site:

https://admin.sharepoint.com/sites/CreatedSubSite

 

From my research I see that I can change the URL of the subsite, but not make a subsite independent of the parent site.

 

I am happy to use PowerShell to facilitate this change.

 

Any help appreciated.

Che

13 Replies

Hello @CheWeigand

 

the only thing that i can find is this article about "Promote subsite into site"

https://sharegate.com/blog/move-subsite-top-level-site-sharepoint 

 

Best, Dave

Hi David,

Didn't want to purchase a app to do something that should be possible in PowerShell. Thanks for your reply.

Che
best response confirmed by CheWeigand (Brass Contributor)
Solution
Hi!

You can't move it straight over but you can use PnP provsinioning to get a template of the site, and then you can apply it to a new site.

https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/introducing-the-pnp-provisioning-...

Content must be moved manually thou :)

Hi Nicholas,

Thanks!
I have worked with PnP before, but it used a Subsite to my Template site. I will read this thoroughly and see if I can apply it to our needs.

Thanks again!
Che
How did it go for you guys? :)
Just got back to this project today. The PnPOnline in Powershell is great. Had to figure out that the -configuration param should refer to a json file, Plus I haven't figured out how to get my Hero webpart pictures from the template to the new site. Menu bar is okay but the site icon is lost.

Any help with the images in the hero webpart would be appreciated.
Thanks
Images from Hero webpart should be located in the site assets, so you can move those over
Same for site Icon, I usually move the items first then use the Invoke-sitetemplate command(or if you're using other commands) :)
Great! I'll try that out now.
Okay - before invoking the template, I changed the thumbnail and site icon, changed the navigation to horizontal and standard.
Still not seeing the hero pictures, although they are listed in Site Assets. Also the 'Theme' color has to be set by me - not being brought from the Template.
I'll keep looking at this - this is a great step forward - I would like less manual setting up, but it will keep our department SP sites similar (we will still allow a department to edit their site).

Thank for all your input. Much appreciated.
Che
Hi Nicolas,
Got everything working.
1. I create new SP site
2. I add Site logo and choose Theme color
3. I run PS script

I needed to reconfigure my JSON config file, once that was done and a new XML file created, the assignment of the template attributes was seamless. I noticed that it took some time for the pictures to appear, but that is not a problem.

Please let me know if you would like me to share the JSON or PS script file.
Thanks again for pointing me in the right direction!
Che
Great job!!

You should create a blogpost about this and other problems you faces, great way to keep track of it and if other people face the same problems.

You can also upload your script here if you want :)

https://pnp.github.io/script-samples/
Thanks, Nicolas!
@NicolasKheirallah
Here's my version of applying a template to a new site.
Hope it's not too buggy. Works for me.
You will need to supply your own JSON and XML file.

Thanks for all your input on this project.

# Managing creation of department SharePoint sites using a standard template
# This script has 4 functions
#============================================================
# Menu Function
#============================================================
Function ShowMenu
{
param([string]$title = 'MenuName')

Clear-Host

Write-Host `n"================ $title =================="`n -ForegroundColor White -BackgroundColor DarkGreen
Write-Host " Enter 1 to: Create New SharePoint Site" -ForegroundColor White -BackgroundColor DarkGreen
Write-Host " Enter 2 to: Create New XML Template File" -ForegroundColor White -BackgroundColor DarkGreen
Write-Host " Enter 3 to: Apply MIU Template to Site" -ForegroundColor White -BackgroundColor DarkGreen
Write-Host " Enter E to: Exit Script"`n -ForegroundColor White -BackgroundColor DarkGreen
}
#=========================================================================================
# Create SharePoint Team Site
#
# This function will create a basic Team site in SPO. The site will have General folders in the Document
# repository, an Attention Issues List, and some Quick links to Knowledge Base.
# You will need to manually update the Site Theme and Header Info.
#=========================================================================================
Function Create_SPO
{
clear-host

$Name = "" # Site name WITH spaces
$Sn = "" # Site name WITHOUT spaces to append to SPO URL
$Own = "" # Owner's Username - ****@miu.edu
$T = "STS#3" # Template Type - use Get-SPOWebTemplate to get a list of valid templates
$SQ = 1024 # Storage Quota - in Megabytes. Can't exceed 25tb (our tenent max quota)
$TZ = 11 # SP Time Zone Collection - https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spregionalsettings.timezones?view=...

Write-Host `n" Create a SharePoint Site "`n -ForegroundColor White -BackgroundColor DarkGreen
do
{
$v = $false
$Name = (Read-Host -Prompt "Please enter a name for your New Site or type E to Exit")
$Sn = $Name -replace '\s', ''

If($Sn -eq '')
{
write-host `n'Name Not Entered.' -ForegroundColor White -BackgroundColor DarkGreen
}
else
{
If($Sn.ToUpper() -eq 'E')
{
$v = $true
}
else
{
# we have a name we need to test to see if name is currently being used
$Url = $Url + $Sn
try{
Get-SPOSite -identity $Url -ErrorAction Stop
#if we DO NOT error out that means there is a SP site with this name already
write-host `n"This name is being used. Please enter a different name."
}
catch{
# Get-SPOSite Errored out - No Site with that name found
$v = $true
}
}
}
}until($v = $true)

if($Sn.ToUpper() -ne 'E')
{
do
{
$v = $false
$Own = (Read-Host `n"Please enter the MIU Username of the Owner or E to Exit")

If($Own.ToUpper() -eq 'E')
{
$v = $true
}
else
{
try
{
Get-MsolUser -UserPrincipalName $Own -ErrorAction Stop
$v = $true
}
catch
{
write-host `n"Username not Found. Re-enter Username"`n -ForegroundColor White -BackgroundColor DarkGreen
}
}
}until($v -eq $true)

# at this point we should either have a (valid site name and valid username) or an E
# only a valid site name and username will trigger the New-SPOSite cmdlet

If($Own.ToUpper() -ne 'E')
{
New-SPOSite -Url $Url -Template $T -Owner $Own -StorageQuota $sq -Title $Name -TimeZoneId $tz -NoWait
}
}
}

#=========================================================================================
# Create New XML File
#
# If you make changes to your SPO Template, you must run this function to update your existing XML file.
# If you do not, the changes you made to the Template will not be applied.
#=========================================================================================
Function Create_XML
{
$c = ""

Write-Host `n "**** Create/Update XML file from SPO Template ****"`n -ForegroundColor white -BackgroundColor darkgreen

$c = (Read-Host -Prompt "Create Xml File? (Y/N)").ToUpper()

if ($c -eq "Y")
{
Connect-PnpOnline -Credential $Cr -Url $Tsite

Get-PnPSiteTemplate -Configuration $jsonPath -Out $xmlPath

Write-Host `n"*** XML created and saved in " + $xmlPath +" ***"`n -ForegroundColor white -BackgroundColor darkgreen
}
}

#=========================================================================================
# Apply Template to New Site
#
# This Function requests the name of any SPO site where you want to apply the Template attributes.
#=========================================================================================
Function Apply_Template
{
$NewSite = ""
$c = ""

Write-Host `n "**** Apply Template Attributes to SP Site ****"`n -ForegroundColor white -BackgroundColor darkgreen

$c = (Read-Host -Prompt "Apply XML Template to a site?(Y/N)")

If($c.ToUpper() -eq "Y")
{
do
{
$Newsite = (Read-Host -Prompt "Please enter a name of the Site to apply the template or E to Exit")
$Newsite = $Newsite -replace '\s', ''

If($NewSite -eq '')
{
write-host `n'Please enter a Site Name or E to exit' -ForegroundColor White -BackgroundColor DarkGreen
}
}until($NewSite -ne '')

if($NewSite -ne 'E')
{
$newSite = $Url + $NewSite

Connect-PnpOnline -Credential $Cr -Url $Newsite
Invoke-PnPSiteTemplate -Path $xmlPath

Write-Host `n"*** Tempate Applied - Please update Site Thumbnail, Logo, and Theme ***"`n -ForegroundColor white -BackgroundColor darkgreen
}
}
}

#=========================================================================================
# Script to call above functions
#=========================================================================================
Clear-Host
# replace ***** with your credential file name
$Cr = Import-Clixml -Path "${env:\userprofile}\*****.xml"

[string]$Url = "https://<Your SP site>.sharepoint.com/sites/"
[string]$Tsite = "https://<Your SP site>.sharepoint.com/sites/Your SiteTemplate Name"
[string]$jsonPath = "C:\Users\SharePoint\Site Templates\SPTemplate.json"
[string]$xmlPath = "C:\Users\SharePoint\Site Templates\PnPOutFile.xml"

write-host "To create a new SPO site, You MUST sign into MSOL and SPO services with your Credentials"`n -ForegroundColor White -BackgroundColor DarkGreen

$ask = (Read-host "Connect to MS Modules with Credentials? (Y/N)")

if($ask.ToUpper() -eq 'Y')
{
Connect-MsolService -Credential $Cr
Connect-SPOService -Credential $Cr -Url "https://<Your Admin SP site>.sharepoint.com/"
}

do
{
$inp = ""
ShowMenu -title "SharePoint Online Template App"
$inp = (Read-host "Please make a selection")

switch ($inp)
{
'1' {Create_SPO}
'2' {Create_XML}
'3' {Apply_Template}
}
}until($inp.ToUpper() -eq 'E')

write-host `n"***** Exiting Script *****"`n -ForegroundColor White -BackgroundColor DarkGreen
1 best response

Accepted Solutions
best response confirmed by CheWeigand (Brass Contributor)
Solution
Hi!

You can't move it straight over but you can use PnP provsinioning to get a template of the site, and then you can apply it to a new site.

https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/introducing-the-pnp-provisioning-...

Content must be moved manually thou :)

View solution in original post