In my sharepoint powershell script: I am retracting the webpart, then removing the webpart, then adding (and deploying it). When I retract it, I have to wait until it finishes before I can move on. I am doing an infinite loop and i want to catch the error. If there is error, then wait, and try again, if no error, then break and move on. The issue is that the try catch is not catching the error. (about you can't make a change when theres an ongoing process).
Does anyone know how to fix this?
Thanks.
function RETRACT()
{
./retractwebpart.ps1
}
function REMOVE()
{
./removewebpart.ps1
}
function ADD()
{
./addwebpart.ps1
}
RETRACT
do
{
try
{
REMOVE -ErrorAction Stop
Break
}
Catch [System.Exception]
{
Start-Sleep -m 1000
}
}
while ($true)
do
{
try
{
ADD -ErrorAction Stop
Break
}
Catch [System.Exception]
{
Start-Sleep -m 1000
}
}
while ($true)
Retract file
# Retracting the solution from web application http://mydomain
Write-Host "Retracting the solution from web application http://mydomain..."
Uninstall-SPSolution –Identity PDFLibrary.wsp –WebApplication http://mydomain -confirm:$false -ErrorAction Stop
Remove file
# Removing the solution from web application http://mydomain
Write-Host "Removing the solution from web application http://mydomain..."
Remove-SPSolution –Identity PDFLibrary.wsp -confirm:$false -ErrorAction Stop
Add file
# Adding the solution to SharePoint
Write-Host "Adding the solution to SharePoint..."
Add-SPSolution C:/PDFLibrary/PDFLibrary.wsp
# Deploying the solution to web application http://mydomain
Write-Host "Deploying the solution to web application http://mydomain..."
Install-SPSolution –Identity PDFLibrary.wsp –WebApplication http://mydomain –GACDeployment