Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Need help with smart entrapment of errors

$
0
0

Hey again!

I am now working on silently installing a suite of programs, and I've been looking a lot at Chocolatey. It seems great, it seems perfect, but it is not good at waiting for one required install to finish before starting the next one.

So I wrote the following myself:

 

try {
  Invoke-Expression -Command '\\FileShare\VS2010SP1\setup.exe /passive /norestart'
  #Install-ChocolateyPackage 'Visual Studio SP1' 'exe' '/passive /norestart' '\\FileShare\VS2010SP1\setup.exe' -validExitCodes @(0)
  do{
    Write-Host "Waiting for $program to finish installing!!"
    Start-Sleep -Seconds 30
  }while(Get-Process setup)
}catch {$fail = $True}
if (-not $fail){
  Write-ChocolateySuccess '$($program)'
}
 
It's not a very "PowerShellish" way to do it, but it's what I've managed to get working so far. My problem here is that when Get-Process setup doesn't find setup, I was hoping I could somehow catch that error, but avoid catching any other errors which I would have liked to get to the prompt. (I.E. when the install fails or hangs...)
Any ideas, suggestions?

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles