I ran this powershell which automates wsp addition, activate, deploy web parts and it runs fine. However, it takes about 3 minutes to go through the whole process. Is this norm?
= = = powershell code = = =
$retractingPackage=""
function FindInstallationType([string] $WSPName, [string] $VersionNo)
{
$Tokens = [regex]::Split($WSPName, "\d{1,}\.\d{1,}\.\d{1,}")
#Note: script assumes that the base package name is always unique
$BasePackageName = $Tokens[0]
$WSP = Get-SPSolution | where {
($_.Name -match $BasePackageName)
}
if ($WSP -match "\d{1,}\.\d{1,}\.\d{1,}") {
#store the analyzing package name for future reference
$global:retractingPackage = $WSP.Name
$VC0 = New-Object System.Version($matches[0])
$VC1 = New-Object System.Version($VersionNo)
Write-Host 'Package version in the solution store:' $VC0
Write-Host 'Package version to be deployed:' $VC1
return $VC1.CompareTo($VC0)
}
# Fresh install
return [Int]2
}
function WaitForJobToFinish([string]$SolutionFileName)
{
$JobName = "*solution-deployment*$SolutionFileName*"
$job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
$maxwait = 30
$currentwait =0
if ($job -eq $null)
{
Write-Host -f Red 'Timer job not found'
}
else
{
$JobFullName = $job.Name
Write-Host -NoNewLine "Waiting to finish job $JobFullName"
while (($currentwait -lt $maxwait))
{
Write-Host -f Green -NoNewLine .
$currentwait = $currentwait + 1
Start-Sleep -Seconds 2
if ((Get-SPTimerJob $JobFullName) -eq $null){
break;
}
}
Write-Host -f Green "....Done!"
}
}
function DeployWspPackage([string]$SolutionPath,[string]$SolutionName)
{
Write-Host -NoNewLine "Adding solution:" $SolutionName
Add-SPSolution $SolutionPath
Write-Host -f Green "....Done!"
Write-Host -NoNewLine "Does the solution contain any web application-specific resources to deploy?"
$WSP = Get-SPSolution | where {
($_.Name -match $SolutionName)
}
if($WSP.ContainsWebApplicationResource)
{
Write-Host -f Yellow "....Yes!"
Write-Host -NoNewLine "Installing the solution for all web applications:" $SolutionName
Install-SPSolution -Identity $SolutionName -AllWebApplications -GACDeployment
}
else
{
Write-Host -f Yellow "....No!"
Write-Host -NoNewLine "Globally deploying the solution:" $SolutionName
Install-SPSolution -Identity $SolutionName -GACDeployment
}
Write-Host -f Green "....Done!"
#Waiting for job to finish
WaitForJobToFinish
if ($SolutionName -match "kwizcom sharepoint foundation")
{
Write-Host -NoNewLine "Installing in central administration site:" $SolutionName
$caID = Get-spwebapplication -includecentraladministration | where {$_.DisplayName -eq "SharePoint Central Administration v4"}
Install-SPSolution -Identity $SolutionName -WebApplication $caID -Force -GACDeployment
Write-Host -f Green "....Done!"
}
}
function RetractWspPackage([string]$SolutionName)
{
Write-Host 'Uninstalling solution:' $SolutionName
Write-Host -NoNewLine "Does the solution contain any web application-specific resources to deploy?"
$WSP = Get-SPSolution | where {
($_.Name -match $SolutionName)
}
if($WSP.ContainsWebApplicationResource)
{
Write-Host -f Yellow "....Yes!"
Write-Host -NoNewLine "Uninstalling the solution from all web applications:" $SolutionName
Uninstall-SPSolution -identity $SolutionName -allwebapplications -Confirm:$false
Write-Host -f Green "....Done!"
}
else
{
Write-Host -f Yellow "....No!"
Uninstall-SPSolution -identity $SolutionName -Confirm:$false
Write-Host -f Green "....Done!"
}
#Waiting for job to finish
WaitForJobToFinish
if ($SolutionName -match "kwizcom sharepoint foundation")
{
Write-Host -NoNewLine "Uninstalling from central administration site:" $SolutionName
$caID = Get-spwebapplication -includecentraladministration | where {$_.DisplayName -eq "SharePoint Central Administration v4"}
Uninstall-SPSolution -Identity $SolutionName -WebApplication $caID -Confirm:$false
Write-Host -f Green "....Done!"
}
#Waiting for job to finish
WaitForJobToFinish
Write-Host -NoNewLine 'Removing solution:' $SolutionName
Remove-SPSolution -Identity $SolutionName -Confirm:$false
Write-Host -f Green "....Done!"
}
function DoDowngradeYesOrNo
{
param([string]$title="Confirm",[string]$message="Are you sure you want to downgrade?")
$choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Answer Yes."
$choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Answer No."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceYes, $choiceNo)
$result = $Host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result)
{
0
{
return $true
}
1
{
return $false
}
}
}
# Check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
Write-Host 'Retreiving just *.wsp files'
$wspFiles=Get-ChildItem . *.wsp|where-object {!($_.psiscontainer)}
foreach($wspFile in $wspFiles){
if ($wspFile.name -match "\d{1,}\.\d{1,}\.\d{1,}" ){
$solutionName = $wspFile.Name
$solutionPath = $wspFile.FullName
# Header
Write-Host '---------------------------------'
Write-Host ''
Write-Host 'Analyzing package:' $solutionName
Write-Host ''
$findInstallationType= (FindInstallationType $solutionName $matches[0])
switch ($findInstallationType) {
-1 {
#Downgrade
if(DoDowngradeYesOrNo){
RetractWspPackage($global:retractingPackage)
DeployWspPackage $solutionPath $solutionName
}
else{
Write-Host 'WSP Package' $wspFile.name 'was skipped.'
}
}
0 {
#Up to date
#RetractWspPackage($global:retractingPackage)
Write-Host 'WSP Package' $wspFile.name 'is up-to-date. No action was taken.'
}
1 {
#Upgrade
RetractWspPackage($global:retractingPackage)
DeployWspPackage $solutionPath $solutionName
}
2 {
#Fresh Install
DeployWspPackage $solutionPath $solutionName
}
}
}
else{
Write-Host 'WSP Package' $wspFile.name 'does not follow the right naming convention. Please correct the issue and run the installation again.'
}
}
Remove-PsSnapin Microsoft.SharePoint.PowerShell