使用PowerShell自动部署解决方案

时间:2011-09-13 06:17:14

标签: sharepoint powershell

我有一个文件夹,其中包含一些SharePoint应用程序的解决方案,我想添加和安装它。我想迭代文件夹中的元素,然后使用Add-SPSolution。在此之后,我想在使用Install-SPSolution之前检查解决方案是否已完成部署。这是我目前正在处理的片段:

   # Get the location of the folder you are currently in
    $dir = $(gl)

    # Create a list with the .wsp solutions
    $list = Get-ChildItem $dir | where {$_.extension -eq ".wsp"}

    Write-Host 'DEPLOYING SOLUTIONS...'
    foreach($my_file in Get-ChildItem $list){Add-SPSolution -LiteralPath $my_file.FullName}

    Write-Host 'SLEEP FOR 30 SECONDS'
    Start-Sleep -s 30

    Write-Host 'INSTALLING SOLUTIONS...'
    foreach($my_file in Get-ChildItem $list){Install-SPSolution -Identity $my_file.Name -AllWebApplications -GACDeployment}

有没有办法检查部署是否已完成,是否已准备好开始安装解决方案?

1 个答案:

答案 0 :(得分:1)

您需要在循环中检查SPSolution.Deployed property值 - 基本解决方案如下所示:

do { Start-Sleep 2 } while (!((Get-SPSolution $name).Deployed))

Deploying SharePoint 2010 Solution Packages Using PowerShell文章包含更多详细信息,this comment讨论了潜在的警告。