当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何在 SharePoint 中使用 PowerShell 部署多个 WSP 解决方案?

作者:精品下载站 日期:2024-12-14 14:01:02 浏览:14 分类:玩电脑

如何在 SharePoint 中使用 PowerShell 部署多个 WSP 解决方案?


要求:我有一堆 WSP 解决方案包,必须将它们全部添加并部署到克隆的 SharePoint 环境中。

解决方案:让我们使用 PowerShell 将文件夹中的所有 WSP 解决方案批量部署到 SharePoint。

用于批量添加多个解决方案的 PowerShell 脚本:

部署 WSP 解决方案是 SharePoint 管理员的一项常见任务。尽管有很多方法可以实现此目的,但当您需要同时部署多个 WSP 时,使用 PowerShell 会特别方便。本文将向您展示如何在 SharePoint 中使用 PowerShell 部署多个 WSP 解决方案。


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

Function WaitForInsallation([string] $SolutionName)
{
        Write-Host -NoNewline "Waiting for deployment job to complete" $SolutionName "."
        $WSPSol = Get-SPSolution $SolutionName
        while($wspSol.JobExists)
        {
            sleep 2
            Write-Host -NoNewline "."
            $wspSol = Get-SPSolution $SolutionName
        }
        Write-Host "job Completed" -ForegroundColor green
}

Function Deploy-SPSolution ($WSPFolderPath)
{
    #Get all wsp files from the given folder
    $WSPFiles = Get-childitem $WspFolderPath | where {$_.Name -like "*.wsp"}

    #Iterate through each wsp and Add in to the solution store
    ForEach($File in $wspFiles)
    {
        $wsp = Get-SPSolution | Where {$_.Name -eq $File.Name}

        if($wsp -eq $null)
        {
            write-host "Adding WSP solution:"$File.Name
            Add-SPSolution -LiteralPath ($WspFolderPath + "\" + $file.Name)
        }
        else
        {
            write-host "solution already exists!"

        }
    }
}

try
{
        Deploy-SPSolution "C:\WSPFiles"
}
catch
{
    write-host $_.exception
} 

添加到 SharePoint 解决方案商店后,您可以使用 PowerShell 将它们部署到目标 Web 应用程序/全局,


Install-SPSolution -Identity "Solution-Name" -Webapplication "Web-App-URL" -GacDeployment -Force

厌倦了手动部署每个解决方案并想找到一种方法来自动化该过程?使用以下脚本一次性部署所有解决方案:


#Deploy all installed solutions in the farm
Get-SPSolution | ForEach-Object { if (!$_.Deployed) {
 If ($_.ContainsWebApplicationResource -eq $False) {
    Install-SPSolution -Identity $_ -GACDeployment 
 }
else {
      Install-SPSolution -Identity $_ -AllWebApplications -GACDeployment 
   }
 }
}

手动部署 SharePoint 解决方案:

您可以从 SharePoint 管理中心站点手动部署。

  • 导航到 SharePoint 2013/2016 管理中心网站。
  • 单击农场管理下的系统设置 >> 管理农场解决方案
  • 从解决方案商店中选择相关解决方案
  • 单击“部署解决方案”开始部署解决方案。

    [玩转系统] 如何在 SharePoint 中使用 PowerShell 部署多个 WSP 解决方案?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯