Skip to content

Commit

Permalink
Merge pull request #1969 from microsoft/dpaul-HcExport
Browse files Browse the repository at this point in the history
Address issue with export issue to xml
  • Loading branch information
dpaulson45 authored Feb 7, 2024
2 parents d2ec3b8 + 756c271 commit 68d9882
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Diagnostics/HealthChecker/Features/Get-HealthCheckerData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,27 @@ function Get-HealthCheckerData {
Write-Progress @paramWriteProgress

try {
$analyzedResults | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction SilentlyContinue
$analyzedResults | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop
Write-Verbose "Successfully export out the data"
} catch {
Write-Verbose "Failed to Export-Clixml. Converting HealthCheckerExchangeServer to json"
$jsonHealthChecker = $analyzedResults.HealthCheckerExchangeServer | ConvertTo-Json

$testOutputXml = [PSCustomObject]@{
HealthCheckerExchangeServer = $jsonHealthChecker | ConvertFrom-Json
HtmlServerValues = $analyzedResults.HtmlServerValues
DisplayResults = $analyzedResults.DisplayResults
try {
Write-Verbose "Failed to Export-Clixml. Inner Exception: $_"
Write-Verbose "Converting HealthCheckerExchangeServer to json."
$jsonHealthChecker = $analyzedResults.HealthCheckerExchangeServer | ConvertTo-Json -Depth 6 -ErrorAction Stop

$testOutputXml = [PSCustomObject]@{
HealthCheckerExchangeServer = $jsonHealthChecker | ConvertFrom-Json -ErrorAction Stop
HtmlServerValues = $analyzedResults.HtmlServerValues
DisplayResults = $analyzedResults.DisplayResults
}

$testOutputXml | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop
Write-Verbose "Successfully export out the data after the convert"
} catch {
Write-Red "Failed to Export-Clixml. Unable to export the data."
}

$testOutputXml | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop
} finally {
# This prevents the need to call Invoke-CatchActions
Invoke-ErrorCatchActionLoopFromIndex $currentErrors

# for now don't want to display that we output the information if ReturnDataCollectionOnly is false
Expand Down

0 comments on commit 68d9882

Please sign in to comment.