新建个powershell文件,后缀名为sp1 例如:test.sp1
代码如下:
function WaitForJobToFinish([string]$SolutionFileName) { $JobName = "*solution-deployment*$SolutionFileName*" $job = Get-SPTimerJob | ?{ $_.Name -like $JobName } if ($job -eq $null) { Write-Host 'Timer job not found' } else { $JobFullName = $job.Name Write-Host -NoNewLine "Waiting to finish job $JobFullName" while ((Get-SPTimerJob $JobFullName) -ne $null) { Write-Host -NoNewLine . Start-Sleep -Seconds 2 } Write-Host "Finished waiting for job.." } } function DeleteTimerJob([string]$SolutionFileName) { $JobName = "*solution-deployment*$SolutionFileName*" $job = Get-SPTimerJob | ?{ $_.Name -like $JobName } if ($job -ne $null) { Write-Host 'Existing Timer job found. Deleting' $job.Delete() } } $url=$args[0] $solutionName="Visigo.Sharepoint.FormsBasedAuthentication.wsp" $featureName="FBAManagement" $solutionPath=$pwd.ToString() + "\" + $solutionName .\UnDeploy.ps1 $url Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue DeleteTimerJob($SolutionName) Write-Host 'Going to add solution' Add-SPSolution $solutionPath Write-Host 'Going to install solution to all web applications' Install-SPSolution –identity $solutionName –allwebapplications –GACDeployment Write-Host 'Waiting for job to finish' WaitForJobToFinish($SolutionName) Write-Host 'Going to enable Feature' Enable-spfeature -identity $featureName -confirm:$false -url $url
部署如下:
右击文件选择运行在powershell切换到ps1文件夹
./Deploy.ps1 "http://yoursite"
卸载代码如下
function WaitForJobToFinish([string]$SolutionFileName) { $JobName = "*solution-deployment*$SolutionFileName*" $job = Get-SPTimerJob | ?{ $_.Name -like $JobName } if ($job -eq $null) { Write-Host 'Timer job not found' } else { $JobFullName = $job.Name Write-Host -NoNewLine "Waiting to finish job $JobFullName" while ((Get-SPTimerJob $JobFullName) -ne $null) { Write-Host -NoNewLine . Start-Sleep -Seconds 2 } Write-Host "Finished waiting for job.." } } function DeleteTimerJob([string]$SolutionFileName) { $JobName = "*solution-deployment*$SolutionFileName*" $job = Get-SPTimerJob | ?{ $_.Name -like $JobName } if ($job -ne $null) { Write-Host 'Existing Timer job found. Deleting' $job.Delete() } } Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $url=$args[0] $solutionName="Visigo.Sharepoint.FormsBasedAuthentication.wsp" $featureName="FBAManagement" $featureExists = Get-SPSolution $solutionName -ErrorAction SilentlyContinue if ($featureExists) { DeleteTimerJob($solutionName) Write-Host 'Going to disable feature' disable-spfeature -identity $featureName -confirm:$false -url $url Write-Host 'Going to uninstall feature' uninstall-spfeature -identity $featureName -confirm:$false -force Write-Host 'Going to uninstall solution' Uninstall-SPSolution -identity $solutionName -allwebapplications -confirm:$false Write-Host 'Waiting for job to finish' WaitForJobToFinish($solutionName) Write-Host 'Going to remove solution' Remove-SPSolution –identity $solutionName -confirm:$false } else { Write-Host 'Solution not installed' }
代码和部署差不多.
注意:一定要把安装的文件包和他放在一块