1

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 ?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
Haithem KAROUI
  • 1,533
  • 4
  • 18
  • 39

2 Answers2

0

After Add-SPSolution try Install-SPSolution

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

Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
  • As described in my post... that was what i have tried and it did not work because the template.wsp was not in the solution gallery and did not figured on the custom templates list – Haithem KAROUI Aug 14 '14 at 07:29
0

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)
Abs
  • 1,339
  • 2
  • 12
  • 16