In this post we are going to see how we can save list as a template that saves it to the list template gallery and then how we can create a new list / library from the template from the saved template earlier.
Here is a simple script that we can write in PowerShell to do that
Here we are saving shared documents library as a template and then creating a library from the saved template.
[xml]$xmlfile = Get-Content ConfigFile.xml
foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{
$site = $sitecoll.name
}
$spSite= Get-SPSite $site
$web = $spSite.OpenWeb()
Write-Host -foregroundcolor yellow 'Saving list as a template.....'
$list = $web.GetList("/sites/SharePointSite/Shared Documents/")
$list.SaveAsTemplate("SDWITHDOCSET","SD with DOCSET","Shared Doc with Doc Set",1)
Write-Host -foregroundcolor Green 'Saving list as a template successfully'
Write-Host -foregroundcolor yellow 'Creating documents library from the template...'
$listTemplates = $spSite.GetCustomListTemplates($web)
$web.Lists.Add("SDFromTemplateUsingPS", "", $listTemplates["SD with DOCSET"])
Write-Host -foregroundcolor green 'Creating documents library from the template completed successfully.'
I hope this helps.
Here is a simple script that we can write in PowerShell to do that
Here we are saving shared documents library as a template and then creating a library from the saved template.
[xml]$xmlfile = Get-Content ConfigFile.xml
foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{
$site = $sitecoll.name
}
$spSite= Get-SPSite $site
$web = $spSite.OpenWeb()
Write-Host -foregroundcolor yellow 'Saving list as a template.....'
$list = $web.GetList("/sites/SharePointSite/Shared Documents/")
$list.SaveAsTemplate("SDWITHDOCSET","SD with DOCSET","Shared Doc with Doc Set",1)
Write-Host -foregroundcolor Green 'Saving list as a template successfully'
Write-Host -foregroundcolor yellow 'Creating documents library from the template...'
$listTemplates = $spSite.GetCustomListTemplates($web)
$web.Lists.Add("SDFromTemplateUsingPS", "", $listTemplates["SD with DOCSET"])
Write-Host -foregroundcolor green 'Creating documents library from the template completed successfully.'
I hope this helps.
No comments:
Post a Comment