From 70989f2c199b75365deb8cb892206061141c0f18 Mon Sep 17 00:00:00 2001 From: Paul Cunningham Date: Thu, 22 Sep 2016 15:20:19 +1000 Subject: [PATCH] Fixed error handling --- Install-OfficeCTR.ps1 | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Install-OfficeCTR.ps1 b/Install-OfficeCTR.ps1 index 7107792..0791111 100644 --- a/Install-OfficeCTR.ps1 +++ b/Install-OfficeCTR.ps1 @@ -71,28 +71,30 @@ param ( $ConfigurationXML = "$($InstallRoot)\$($SKU)\$($Channel)\configuration.xml" -try { - Test-Path $ConfigurationXML -ErrorAction STOP -} -catch { +If (!(Test-Path $ConfigurationXML)) { throw "Unable to locate a configuration XML file at $($ConfigurationXML)" } $setuppath = "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe" -try { -} -catch { +if (!(Test-Path $setuppath)) { throw "Unable to locate a Setup.exe file at $($setuppath)" } Write-Host "Attempting to install Office 365 $($SKU) $($Channel)" -$process = Start-Process -FilePath "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe" -ArgumentList "/Configure $($InstallRoot)\$($SKU)\$($Channel)\configuration.xml" -Wait -PassThru -if ($process.ExitCode -eq 0) -{ - Write-Host -ForegroundColor Green "Office setup started without error." + +try { + $process = Start-Process -FilePath "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe" -ArgumentList "/Configure $($InstallRoot)\$($SKU)\$($Channel)\configuration.xml" -Wait -PassThru -ErrorAction STOP + + if ($process.ExitCode -eq 0) + { + Write-Host -ForegroundColor Green "Office setup started without error." + } + else + { + Write-Warning "Installer exit code $($process.ExitCode)." + } } -else -{ - Write-Warning "Installer exit code $($process.ExitCode)." +catch { + Write-Warning $_.Exception.Message }