upload site template wsp file powershell

2.5k views Asked by At

I am using SharePoint 2013 and i want to create some spweb from a site template...

I have created a site and added my desired content and i saved that site as template, then went to solution gallery and downloaded the .wsp file.

Now, i need to create a new site collection with some subsites which are based on that template, and to do so i think need to upload the .wsp file to the solution gallery the way i can find the newly saved template, and i need to do that from PowerShell !

I tried 2 ways,

First,

I tried to add-spsolution and install-spsolution like following

Add-SPSolution -LiteralPath $SPIntranetTemplateFilePath
Install-SPSolution -Identity SPITemplateFile.wsp -CompatibilityLevel 15 -force

but i don't find the .wsp in the solution gallery and the template is not in templates list...

I tried to use Install-SPWebTemplate but this command is not recognized as a cmdlet in my PowerShell (I have added Add-PSSnapin Microsoft.SharePoint.PowerShell)

I have used this too

## SharePoint DLL 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

Can anyone help me to use my WspFile the way i can create subsites based on my template ?

2

There are 2 answers

1
Andy Arismendi On

After Add-SPSolution try Install-SPSolution

http://technet.microsoft.com/en-us/library/ff607534(v=office.15).aspx

0
Abs On

I think you need to add it as a sandboxed user solution for it to show up in the site collection's solution gallery. This approach worked for me.

$theSite = Get-SPSite "http://server/pathto/site"
# add the solution to the sandbox
Add-SPUserSolution (Resolve-Path .\relativePathTo.wsp) -Site $theSite 
# get the user solution and activate it for the site
$customSolution = Get-SPUserSolution -Site $theSite | ? { $_.Title -match "Custom Template Title" }
Install-SPUserSolution $customSolution -Site $theSite

Once you have the sandboxed solution installed, the trick to using it to create a subsite is to use the object model to grab the template.

$localeId = 1033 # or whatever is appropriate for you
$customTemplate = $theSite.RootWeb.GetAvailableWebTemplates($localeId) | ? { $_.Title -match "Custom Template Title" } 

Now, you can create a subsite based on NO template at all, and then apply the custom template:

$newSubsite = $New-SPWeb "http://server/pathto/site/subsite" # can also apply options for unique permissions, nav bar, etc.
$newSubsite.ApplyWebTemplate($customTemplate)