Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to deploy a WSP and activate a SharePoint Feature with Powershell - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2013-06-06

Here is a Powershell Script to that deploys a WSP and activates a SharePoint feature

$solutionName="solutionname.wsp"
$featureName="featurename"
$SolutionPath="C:\wsp\"+$solutionName

if($args[0] -eq 'DEV') {
$webAppName="http://url"
}
elseif ($args[0] -eq 'QA') {
$webAppName="http://url"
}
elseif ($args[0] -eq 'PROD') {
$webAppName="http://url"
}
else {
Write-Host "$(Get-Date -Format o) Environment not specified - please pass appropriate environment to deploy -"
exit
}

Function WaitForJobToFinish[string]$SolutionFileName)
{ 
$JobName = "*solution-deployment*$SolutionFileName*"
$job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
if ($job -eq $null) 
{
Write-Host 'Timer job not found'
}
else
{
$JobFullName = $job.Name
Write-Host -NoNewLine "Waiting to finish job $JobFullName"

while ((Get-SPTimerJob $JobFullName) -ne $null) 
{
Write-Host -NoNewLine .
Start-Sleep -Seconds 2
}
Write-Host "Finished waiting for job.."
}
}

$powershellSnapin = "Microsoft.Sharepoint.Powershell"

if ((Get-PSSnapin -Name $powershellSnapin -ErrorAction SilentlyContinue) -eq $null )
{
Write-Host "--------------------------------- Adding sharpoint powershell snapin if not existing-------------------------"
Add-PsSnapin $powershellSnapin
}

if($DeployWebURL -eq '')
{
Write-Host "$(Get-Date -Format o) Incorrect Environment specified - please pass 'DEV/QA/PROD' -"
exit
}

Write-Host 'Going to disable feature ' $featureName
disable-spfeature -identity $featureName -confirm:$false -url $webAppName

Write-Host 'Going to uninstall feature ' $featureName
uninstall-spfeature -identity $featureName -confirm:$false -force

Write-Host 'Going to uninstall solution '$solutionName
Uninstall-SPSolution -identity $solutionName -confirm:$false

Write-Host 'Waiting for job to finish'
WaitForJobToFinish

Write-Host 'Going to remove solution'
Remove-SPSolution –identity $solutionName -confirm:$false

Write-Host 'Going to add solution '$SolutionPath
Add-SPSolution $SolutionPath

Write-Host 'Going to install solution to web application '$solutionName
Install-SPSolution –identity $solutionName –GACDeployment

do
{
Write-Host “.” -NoNewline -ForeGroundColor Green;
Start-Sleep -Seconds 5; 
try
{
write-host 'Verifying if the solution installation is valid'
$testsolution = Get-SPSolution -Identity $solutionName
}
catch
{}
}while(!$testsolution);

Write-Host 'Going to enable Feature ' $featureName
Enable-spfeature -identity $featureName -confirm:$false -url $webAppName
Write-Host 'Enabled Feature' $featureName
Remove-PsSnapin Microsoft.SharePoint.PowerShell

Save the PS as Deploy.ps1

Change the Parameters required for :

  • $solutionName=”solutionname.wsp”
  • $featureName=”featurename” and
  • $webAppName  accordingly and deploy the commands via .\Deploy.ps1 Dev or .\Deploy QA or .\Deploy.ps1 Prod
(Visited 554 times, 1 visits today)

About the author 

Jayaraja Jayaraman

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.