Praveen_KumarS
Oct 01, 2024Copper Contributor
How to do deployment of WSP Solution using PNP Powershell in SharePoint
Looking for sample code details for below mentioned using PNP PowerShell.
-Uploading WSP file to Solution gallery of Classic SharePoint site
-Installing Solution
-Activating the solution
-Apply the custom template to SharePoint site.
#Below is CSOM based Code - looking for code in PNP Based
$fileBytes =[System.IO.File]::ReadAllBytes("D:\CustomTemplate.wsp")
$fileCreateInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$fileCreateInfo.Content = $fileBytes
$fileCreateInfo.Url = $list.RootFolder.ServerRelativeUrl + "/CustomTemplate.wsp"
$fileCreateInfo.Overwrite = $true
$file = $list.RootFolder.Files.Add($fileCreateInfo)
$Ctx.Load($file)
$Ctx.ExecuteQuery()
$designPackageInfo = New-Object Microsoft.SharePoint.Client.Publishing.DesignPackageInfo
$designPackageInfo.PackageName = "CustomTemplate.wsp"
$WSP = New-Object Microsoft.SharePoint.Client.Publishing.DesignPackageInfo
$WSP.PackageGuid = [System.Guid]::Empty
$WSP.PackageName = "CustomTemplate.wsp"
$WSP.MajorVersion = 1
$WSP.MinorVersion = 0
$WSPFileURL = $list.RootFolder.ServerRelativeUrl + "/" + "CustomTemplate.wsp";
[Microsoft.SharePoint.Client.Publishing.DesignPackage]::Install($Ctx, $Ctx.Site, $WSP, $WSPFileURL)
$Ctx.ExecuteQuery()
Write-Host -f Green "`tInstalled the Solution Successfully!"
#--------------------------------------------------------------------------------
[Microsoft.SharePoint.Client.Publishing.DesignPackage]::Install($Ctx, $site, $designPackageInfo, $fileCreateInfo.Url)
$Ctx.ExecuteQuery()
# Below is the main code to activate template and assign home page in site.
[Microsoft.SharePoint.Client.Publishing.DesignPackage]::Apply($Ctx, $Ctx.Site, $WSP)
$Ctx.ExecuteQuery()
$web = $Ctx.Site.RootWeb
$templateName = “{E7ED6200-07BF-42F8-94CB-F6560D080DFA}#SZ"
$web.ApplyWebTemplate($templateName)
$web.update()
$Ctx.ExecuteQuery()