Search This Blog

Monday, January 22, 2018

SharePoint 2013 - Deployment script


Step :1 Copy and save the below script in DeployWSP.PS1
Step :2 Map the path in bat file and execute
Step: 3 Change the WSP file path
-------------------------------------script--------------------------------------------------------------------

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
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 "F:\JaisonArumugam\WSPPath"
write-host -nonewline "Continue? (Y/N) "
$response = read-host
if ( $response -ne "Y" ) { exit }
}
catch
{
    write-host $_.exception
}


 ---------------------------------------------bat file--------------------------------------------------
save .bat below line and execute run with admin

cd /d %~dp0
powershell -noexit -file "DeployWSP.PS1" "%CD%"
pause

No comments:

Post a Comment