用PowerShell批量删除未部署的wsp包

 提供wsp部署的参数:$wspnames:路径下的所有wsp文件名用逗号隔开,如“sumhtestwsp.wsp,sumhtestwsp123.wsp,sumhtestwsp456.wsp,sumhtestwsp789.wsp”

 

方法:

function RemoveWSP([string] $wspnames)

{

$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 -ne $null)

{

if(!$gspsolution.Deployed)

{

Remove-SPSolution -Identity  $wspname

}

}        

}

}

 

例如:

RemoveWSP -wspnames "sumhtestwsp.wsp,sumhtestwsp123.wsp,sumhtestwsp456.wsp"

你可能感兴趣的:(powershell)