0

I have power shell script which will perform multiple tasks like uninstalling,removing and again installing wsp solutions.I am facing an issue like the first process is taking too long time for uninstalling solution so that other process has to wait till the first action has to get completed fully.Now i am giving sleep time but it has some problem while different machines speed gets varies.. I also aware about calling notepad like an external function but i dont want that has to happen here.Apart from that any solutions are availabe like I need to wait for first process to get complete before starting the second process.

$InstallDIR = "F:\new\source\UpdatedWSPFiles"
$Dir = get-childitem $InstallDIR -Recurse
$WSPList = $Dir | where {$_.Name -like "*.wsp*"}
Foreach ($wsp in $WSPList )
{
$WSPFullFileName = $wsp.FullName
$WSPFileName = $wsp.Name
try
{
Write-Host -ForegroundColor White -BackgroundColor Blue "Working on $WSPFileName"
Write-Host -ForegroundColor Green "Retracting Solution"
Uninstall-SPSolution -AllWebApplications -Identity "$WSPFileName" -Confirm:$false 
sleep 100

Write-Host -ForegroundColor Green "Removing Solution from farm"
Remove-SPSolution -Identity "$WSPFileName" -Confirm:$false -Force
sleep 60

Write-Host -ForegroundColor Green "Adding solution to farm"
Add-SPSolution "$WSPFullFileName"  -Confirm:$false 
sleep 60
}
4

2 回答 2

0

猜你可以试试

Start-Job -Name "jobname" -ScriptBlock { Uninstall-SPSolution -AllWebApplications -Identity "$WSPFileName" -Confirm:$false }

Wait-Job -Name "jobname" -Timeout "maximum wait time"
于 2013-02-05T23:37:34.500 回答
0

您可以尝试使用 -wait 开关启动进程:

    PS> $p="C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    PS> $params="-command &{ if ((Get-PSSnapin `"Microsoft.SharePoint.PowerShell`" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin `"Microsoft.SharePoint.PowerShell`"
}
Uninstall-SPSolution -AllWebApplications -Identity `"$WSPFileName`" -Confirm:$false}"
    PS> Start-Process $p $params -Wait
于 2013-02-04T12:28:03.613 回答