提供wsp部署的参数:
$wsppath:wsp文件所在的路径,如“c:\”
$wspnames:路径下的所有wsp文件名用逗号隔开,如“sumhtestwsp.wsp,sumhtestwsp123.wsp,sumhtestwsp456.wsp,sumhtestwsp789.wsp”
$allwebapp:是否要全局部署,如“$True”,true是要全局部署$webId:$allwebapp为“$False”,那么就需要输入指定应用程序的Guid
方法:
function deployWSP([string] $wsppath,[string] $wspnames,[bool] $allwebapp,[Guid] $webId)
{
$PSSnapinSharePoin = Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction silentlycontinue
if( $PSSnapinSharePoin -eq $Null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
foreach($wspname in $wspnames.split(','))
{
$gspsolution = Get-SPSolution -Identity $wspname -ErrorAction silentlycontinue
if($gspsolution -eq $null)
{
Add-SPSolution -LiteralPath $wsppath.Insert($wsppath.Length,$wspname)
}
if($allwebapp)
{
if(!$gspsolution.Deployed)
{
Install-SPSolution -Identity $wspname -GACDeployment -AllWebApplications
}
}
else
{
if(!$gspsolution.Deployed)
{
Install-SPSolution -Identity $wspname -GACDeployment -WebApplication $webId
}
}
}
}
例如
deployWSP -wsppath "c:\" -wspnames "sumhtestwsp.wsp,sumhtestwsp123.wsp,sumhtestwsp456.wsp" -allwebapp $true