SharePoint 2010 Powershell script to deploy solution,
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile = ".\DeploySolutionPatch-$LogTime.rtf"
# Add SharePoint PowerShell Snapin
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
#Deleting any .rtf files in the scriptbase location
$FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
if($FindRTFFile)
{
foreach($file in $FindRTFFile)
{
remove-item $file
}
}
start-transcript $logfile
$url = ""
$solutionFile = ""
$url = Read-Host "Enter the Web Application Url [e.g. http://server_name]"
$solutionFile = Read-Host "Enter the Solution path [e.g. C:\SharePointProject.wsp]"
Write-host "Add/install Solution to Web Application..."
$file = Get-ChildItem $solutionFile
Add-SPSolution -literalpath $solutionFile
$Solution = Get-SPSolution | ? {($_.Name -eq $file.name) -and ($_.Deployed -eq $false) }
if(($Solution -ne $null) -and ($Solution.ContainsWebApplicationResource) )
{
Install-SPSolution -identity $file.name -WebApplication $url -GACDeployment -Confirm:$false
}
else
{
Install-SPSolution -identity $file.Name -GACDeployment -Confirm:$false
}
while ($Solution.Deployed -eq $false)
{
Start-Sleep 2
}
Write-Host "Deployment completed" -fore yellow 