Subscribe:

Labels

Thursday, September 27, 2018

Install .Stp and create the list using Stp's



# Adding the PowerShell Snapin 
 Add-PSSnapin "Microsoft.SharePoint.PowerShell"    

 # Get the SiteURL  - Configuration
 $site = get-spsite("http://dwst:4444/")     

 # Get the root web 
 $web = $site.RootWeb     

 $spFolder1 = $web.getfolder("_catalogs/lt")
 $spFolder2 = $web.getfolder("_catalogs/lt")
 $spFolder3 = $web.getfolder("_catalogs/lt")

 # Deleting the existing STP files

 $files = $spfolder1.Files | Where-Object {($_.Name -eq "MarketingConfig.stp") -OR
                                             ($_.Name -eq "MarketingContent.stp") -OR
                                             ($_.Name -eq "MarketingProducts.stp")}

foreach ($file in $files)
{  
        $file.Delete()  
        write-host "Deleting the existing list templates"
}


# Deleting the existing SP Lists

 try
 {
 $MarConfigList = $web.lists["MarketingConfig"]
 write-host "Deleting the existing MarketingConfig List"
 $MarConfigList.Delete()
 }
 catch
 {
 
 }
 try
 {
 $MarConfigList = $web.lists["MarketingContent"]
 write-host "Deleting the existing MarketingContent List"
 $MarConfigList.Delete()
 }
 catch
 {
 
 }

 try
 {
 $MarProdList = $web.lists["MarketingProducts"]
  write-host "Deleting the existing MarketingProducts List"
  $MarProdList.Delete()
 }
 catch
 {

 }

 # Get the list template gallery 
 $spLTG = $web.getfolder("List Template Gallery")     

 # Get the list template gallery Collection 
 $spcollection = $spLTG.files     

 # Get the custom list template file  - Configuration
 $Templatefile1 = get-item "C:\Deployment\ListTemplates\MarketingConfig.stp"    
 $Templatefile2 = get-item "C:\Deployment\ListTemplates\MarketingContent.stp"
 $Templatefile3 = get-item "C:\Deployment\ListTemplates\MarketingProducts.stp"

 # Add the custom list template file to gallery 
 $spcollection.Add("_catalogs/lt/MarketingConfig.stp", $Templatefile1.OpenRead(), $true)  
 $spcollection.Add("_catalogs/lt/MarketingContent.stp", $Templatefile2.OpenRead(), $true)
 $spcollection.Add("_catalogs/lt/MarketingProducts.stp", $Templatefile3.OpenRead(), $true)  
 Write-Host "Custom Templates Uploaded to List Template Gallery Successfully" -fore Green
  
 Write-Host “Creating the List based on the Template”  -fore Green   

 # Get the custom list templates  
 $CustomlistTemplates = $site.GetCustomListTemplates($web)

 
 #Create the custom list using template 
 $web.Lists.Add("MarketingConfig", "MarketingConfig", $CustomlistTemplates["MarketingConfig"])
 Write-Host "MarketingConfig List is created" -fore Green  
 $web.Lists.Add("MarketingContent", "MarketingContent", $CustomlistTemplates["MarketingContent"])
 Write-Host "MarketingContent List is created" -fore Green
 $web.Lists.Add("MarketingProducts", "MarketingProducts", $CustomlistTemplates["MarketingProducts"])
 Write-Host "MarketingProducts List is created" -fore Green

 Write-Host "Successfully installed the list templates" -fore Green

No comments:

Post a Comment