# Добавляем решение
function AddInstallSolution($SolutionName) {           
    
    Write-Host "Solution $SolutionName installing..."
    $FullPathToSolution = $executingScriptDirectory+"\" + $SolutionName
    $solution = Add-SPSolution -LiteralPath "$FullPathToSolution"    
    if ($solution.ContainsWebApplicationResource –eq $false) 
    {
      Install-SPSolution $solution -GACDeployment
    } 
    else
    {
      Install-SPSolution $solution -GACDeployment -WebApplication $webAppUrl
    }    
   
    while($solution.Deployed –eq $false)
    {
        Write-Progress -Activity "Working..." -CurrentOperation "$secs s. waiting" -Status "Please wait."
        sleep -s 1
        $secs = $secs + 1
    }
}

cls
# Проверяем наличие аргументов в командной строке их должно быть два: URL сайта и URL коллекции сайтов
if($args[0] -eq $null){
    Write-Host "Error! Empty argument 'siteUrl'! Use like this 'CollaborationSetup.ps1 http://myportal:90'"
    Write-Host " "
    Write-Host "Press any key ..."
    $null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")    
    return
}

Write-Host "Variables initialization ..."
$webAppUrl = $args[0]
$SPAdminTool=$env:CommonProgramFiles + "\Microsoft Shared\web server extensions\14\BIN\stsadm.exe"
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

# Грузим скриптлет SharePoint
Write-Host "SharePoint snapin loading ..."
if(!(Get-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction:SilentlyContinue))
{
    Add-PSSnapin Microsoft.SharePoint.Powershell
}


# Устанавливаем нестрогий контроль файлов у Веб-приложения
Write-Host "Web application BrowserFileHandling configuring ..."
$webapp = Get-SPWebApplication $webAppUrl
$webapp.BrowserFileHandling = “Permissive” # “Strict”
$webapp.update()

# Устанавливаем решения
Write-Host "SharePoint solutions processing ..."
Write-Host "---------------------------------------------------------------"
AddInstallSolution("iLoveSharePoint.Fields.LookupFieldWithPicker.wsp")
Write-Host "---------------------------------------------------------------"
AddInstallSolution("Collaboration.wsp")
Write-Host "---------------------------------------------------------------"


# Выводим сообщение о завершении операций
$shell = New-Object -ComObject Wscript.Shell
$shell.popup("Установка завершена.",0,"Результат" , 64)

Write-Host " "
Write-Host "Press any key ..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")