Tuesday, October 30, 2012

The solution cannot be removed when a job is scheduled or running



This is one of the strange issue when working with sharepoint script files.

Cause for the issue

Usually when we are working with deployment

all the script operation will be executed one after other till the completion of the deployment on the same batch file or powershell file.

This will cause this error because after performing the uninstall or remove wsp file from sharepoint it will take couple of minutes to complete the process.

Untill the operation should be paused.

Solution

This can be handled with the powershell script given below :


function WaitForJobToFinish([string]$SolutionName1)
{
    $JobName = "*solution-deployment*$SolutionName1*"
    $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.."
    }
}




No comments:

Post a Comment