Created
July 8, 2014 10:00
-
-
Save anonymous/e630bb5ecc56f3462819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################### | |
# This script deploys a feature to a SharePoint 2010 farm. # | |
################################################################################################### | |
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ea "SilentlyContinue" | |
$packageName = "XXX.wsp" # The name of the package to deploy | |
$targetDirectory = "C:\XXX" # The directory that contains the package to deploy | |
$siteUrl = "XXX" # The url of the site/site collection the feature is deployed to | |
$webApp = "XXX" # The name of the application or the GUID of the application | |
$featureName = "XXX" # The name of the feature | |
################################################################################################### | |
# Waits for the solution deployment timer job to finish. # | |
################################################################################################### | |
Function Wait-TimerJob | |
{ | |
[CmdletBinding()] | |
param () | |
$job = Get-SPTimerJob | ?{ $_.Name -like "*solution-deployment*" } | |
if ($job -eq $null) | |
{ | |
Write-Host "Solution deployment job not running." | |
} | |
else | |
{ | |
# If it's taking too long, throw an error so problem can be investigated. | |
$timeOut = (Get-Date).AddMinutes(5) | |
while ((Get-SPTimerJob $job.Name) -ne $null) | |
{ | |
Write-Host -NoNewLine . | |
Start-Sleep -Seconds 2 | |
if ((Get-Date) -gt $timeOut) | |
{ | |
$message = "Operation timed out while waiting for the solution deployment timer job to complete." | |
$exception = New-Object System.OperationCanceledException $message | |
$errorId = "TimeOutWaitingForJob" | |
$errorCategory = "OperationTimeout" | |
$target = "Wait-TimerJob" | |
$errorRecord1 = New-Object Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $target | |
$PSCmdlet.ThrowTerminatingError($errorRecord1) | |
} | |
} | |
Write-Host "" | |
} | |
} | |
if ((Get-SPFeature -Site $siteUrl -Identity $featureName -EA SilentlyContinue) -ne $null) | |
{ | |
Write-Host "Disabling feature..." | |
Disable-SPFeature $featureName -Url $siteUrl -force -confirm:$false | |
Write-Host "Feature disabled." | |
} | |
$solutionRef = Get-SPSolution -Identity $packageName -EA SilentlyContinue | |
if ($solutionRef -ne $null) | |
{ | |
if ($solutionRef.Deployed) | |
{ | |
Write-Host "Uninstalling solution..." | |
Uninstall-SPSolution –Identity $packageName –WebApplication $webApp -confirm:$false | |
Wait-TimerJob | |
Write-Host "Solution uninstalled." | |
} | |
Write-Host "Removing solution..." | |
Remove-SPSolution –Identity $packageName -confirm:$false | |
Write-Host "Solution removed." | |
} | |
Write-Host "Adding new solution..." | |
$result = Add-SPSolution $targetDirectory\$packageName | |
Write-Host "Solution added." | |
Write-Host "Installing solution..." | |
Install-SPSolution –Identity $packageName –WebApplication $webApp -GACDeployment -CASPolicies -Force | |
Wait-TimerJob | |
Write-Host "Solution installed." | |
Write-Host "Enabling feature..." | |
Enable-SPFeature $featureName -Url $siteUrl -force | |
Write-Host "Feature enabled." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment