PowerShell: Скрипт для установки/переустановки SharePoint сборок (wsp)
Очень часто в жизни SharePoint разработчика возникает потребность в автоматизации рутинных действий. И пока скрипты работают, можно поделиться с другими разработчиками, полезными наработками. Одна из таких наработок это скрипт который помогает мне, если необходимо переразвернуть или развернуть решения.
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
function DeployPackage($path, $wspname, $webappurl)
{
try
{
$wsp = Get-SPSolution $wspname -ErrorAction silentlycontinue
if ($wsp -ne $null)
{
if($wsp.Deployed)
{
Write-Output "Uninstall $wsp"
if ($wsp.ContainsWebApplicationResource)
{
Uninstall-SPSolution $wsp -Confirm:$false -AllWebApplications
}
else
{
Uninstall-SPSolution $wsp -Confirm:$false
}
while($wsp.JobExists) { Write-Host '.' -NoNewLine; start-sleep -s 5; }; Write-Host;
Write-Output "$wsp uninstalled"
}
Remove-SPSolution $wsp -Force -Confirm:$false
Write-Output "$wsp removed"
}
$wsp = Get-SPSolution $wspname -ErrorAction silentlycontinue
if ($wsp -eq $null)
{
Write-Output "Add $wsp"
$wsp = Add-SPSolution -LiteralPath $path
Write-Output "$wsp added"
if ($wsp.ContainsWebApplicationResource)
{
Write-Output "Install $wsp"
Install-SPSolution $wsp –WebApplication $webappurl -GACDeployment -Force
while($wsp.JobExists) { Write-Host '...' -NoNewLine; start-sleep -s 5; }; Write-Host;
Write-Output "$wsp Installed on $webappurl"
}
else
{
Write-Output "Install $wsp"
Install-SPSolution $wsp -GACDeployment -Force
while($wsp.JobExists) { Write-Host '...' -NoNewLine; start-sleep -s 5; }; Write-Host;
Write-Output "$wsp Installed"
}
}
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
# Перечисляем названия сборок
$wspFiles = @("Portal.wsp", "Portal.Company.wsp", "CommonService.wsp", "Directum.wsp", "Portal.Core.wsp");
# Адрес веб приложения
$webappurl = "http://localhost/"
# Путь до сборок
$folder = "C:\tmp"
foreach ($wspname in $wspFiles) {
$path= $folder + "\" + $wspName
DeployPackage $path $wspname $webappurl
}
Write-Output "Restarting IIS and Timer Service..."
iisreset
net stop SPTimerV4
net start SPTimerV4
Comments
Post a Comment