alejandro-g
5/22/2017 - 7:18 PM

Install sharepoint webpart: this script 1) make a backup of current webpart deployed, 2) remove previous webpart, 3) add the new wsp, 4) dep

Install sharepoint webpart: this script 1) make a backup of current webpart deployed, 2) remove previous webpart, 3) add the new wsp, 4) deploy the new wsp

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition

function InstallWebparts(){
    [CmdletBinding()]            
    Param(            
    [Parameter(Mandatory=$true)]  
    [string]$website,
    [Parameter(Mandatory=$true)]
    [string]$webpartName,
    [Parameter(Mandatory=$true)]
    [string]$webpartPath
    )
	
	#$sln = get-spsolution -identity $webpartName
	$sln = get-spsolution | where { $_.name -eq $webpartName }
	if ($sln -ne $null){		
	    echo "creando respaldo del archivo wsp actual de $webpartName"
		$bkpFolder =  "$($scriptPath)\bkp\" + [System.DateTime]::Now.ToString("yyyy-MM-dd")
		if ((test-path -path $bkpFolder) -eq $false){		
			New-Item -ItemType Directory -Path $bkpFolder > $null
		}
		$sln.SolutionFile.SaveAs("$bkpFolder\$webpartName")
		echo "respaldo creado en: $bkpFolder\$webpartName"		
	    echo "deinstalando el webpart existente $webpartName" 
		#Uninstall-SPSolution -Identity $webpartName -WebApplication $website -confirm:$false
		Uninstall-SPSolution -Identity $webpartName -AllWebApplications:$true -confirm:$false		
		while($sln.JobExists) { 
			echo " > desinstalacion en proceso..."
			start-sleep -s 10 
		}			
		
		Write-Host -f White "removiendo webpart"
		Remove-SPSolution -Identity $webpartName -confirm:$false
	}		
	
    Write-Host -f White "Agregando la solucion $webpartName al espacio de almacenamiento de sharepoint"
    Add-SPSolution -LiteralPath $webpartPath
    Write-Host -f White "solucion agregada"
    Write-Host -f White " "
    Write-Host -f White -nonewline "instalando la solucion "

	$sln =  get-spsolution -identity $webpartName
	if ($sln.ContainsWebApplicationResource){
		write-host -f yellow "modo: webapp"
		Install-SPSolution -Identity $webpartName -WebApplication $website -GacDeployment
	} else {
		write-host -f yellow "modo: farm"
	    Install-SPSolution -Identity $webpartName -GacDeployment
	}	
	
    $sln =  get-spsolution -identity $webpartName
    while($sln.JobExists) { 
      Write-Host " > instalacion en proceso..."
      start-sleep -s 10 
    }
    Write-Host -f Green "instalacion finalizada"
}