diff --git a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 index 42a856d01e..6e422a4168 100644 --- a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 +++ b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerOsInformation.ps1 @@ -173,6 +173,13 @@ function Invoke-AnalyzerOsInformation { } Add-AnalyzedResultInformation @params } + + $params = $baseParams + @{ + Details = "More Information: https://aka.ms/HC-NetFrameworkSupport" + DisplayWriteType = "Yellow" + DisplayCustomTabNumber = 2 + } + Add-AnalyzedResultInformation @params } $displayValue = [string]::Empty diff --git a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeAppPoolsInformation.ps1 b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeAppPoolsInformation.ps1 index 6e977ffb76..881b78d629 100644 --- a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeAppPoolsInformation.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeAppPoolsInformation.ps1 @@ -26,7 +26,7 @@ function Get-ExchangeAppPoolsInformation { $FilePath ) if (Test-Path $FilePath) { - return (Get-Content $FilePath -Raw).Trim() + return (Get-Content $FilePath -Raw -Encoding UTF8).Trim() } return [string]::Empty } ` diff --git a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeServerIISSettings.ps1 b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeServerIISSettings.ps1 index 414e7c8540..91e28bb46d 100644 --- a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeServerIISSettings.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-ExchangeServerIISSettings.ps1 @@ -63,7 +63,7 @@ function Get-ExchangeServerIISSettings { $content = $null try { if ($exist) { - $content = (Get-Content $_ -Raw).Trim() + $content = (Get-Content $_ -Raw -Encoding UTF8).Trim() [xml]$content | Out-Null # test to make sure it is valid $validWebConfig = $true } diff --git a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebApplication.ps1 b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebApplication.ps1 index 6599c6cd89..492ed7e7e9 100644 --- a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebApplication.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebApplication.ps1 @@ -36,7 +36,7 @@ function Get-IISWebApplication { $webConfigExists = Test-Path $configurationFilePath if ($webConfigExists) { - $webConfigContent = (Get-Content $configurationFilePath -Raw).Trim() + $webConfigContent = (Get-Content $configurationFilePath -Raw -Encoding UTF8).Trim() try { $linkedConfigurationLine = ([xml]$webConfigContent).configuration.assemblyBinding.linkedConfiguration.href diff --git a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebSite.ps1 b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebSite.ps1 index 8f4de3f8f1..81dc346ef8 100644 --- a/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebSite.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ExchangeInformation/IISInformation/Get-IISWebSite.ps1 @@ -54,7 +54,7 @@ function Get-IISWebSite { $customHeaderHsts = $null if ($webConfigExists) { - $webConfigContent = (Get-Content $configurationFilePath -Raw).Trim() + $webConfigContent = (Get-Content $configurationFilePath -Raw -Encoding UTF8).Trim() try { $webConfigContentXml = [xml]$webConfigContent diff --git a/Diagnostics/HealthChecker/Features/Get-HealthCheckerData.ps1 b/Diagnostics/HealthChecker/Features/Get-HealthCheckerData.ps1 index ad7c15cfe7..bcc2a6bbb1 100644 --- a/Diagnostics/HealthChecker/Features/Get-HealthCheckerData.ps1 +++ b/Diagnostics/HealthChecker/Features/Get-HealthCheckerData.ps1 @@ -45,6 +45,58 @@ function Get-HealthCheckerData { return $false } + function ExportHealthCheckerXml { + [CmdletBinding()] + [OutputType([bool])] + param( + [Parameter(Mandatory = $true)] + [object]$SaveDataObject, + + [Parameter(Mandatory = $true)] + [hashtable]$ProgressParams + ) + Write-Verbose "Calling: $($MyInvocation.MyCommand)" + $dataExported = $false + + try { + $currentErrors = $Error.Count + $ProgressParams.Status = "Exporting Data" + Write-Progress @ProgressParams + $SaveDataObject | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop -Force + Write-Verbose "Successfully export out the data" + $dataExported = $true + } catch { + try { + Write-Verbose "Failed to Export-Clixml. Inner Exception: $_" + Write-Verbose "Converting HealthCheckerExchangeServer to json." + $outputXml = [PSCustomObject]@{ + HealthCheckerExchangeServer = $null + HtmlServerValues = $null + DisplayResults = $null + } + + if ($null -ne $SaveDataObject.HealthCheckerExchangeServer) { + $jsonHealthChecker = $SaveDataObject.HealthCheckerExchangeServer | ConvertTo-Json -Depth 6 -ErrorAction Stop + $outputXml.HtmlServerValues = $SaveDataObject.HtmlServerValues + $outputXml.DisplayResults = $SaveDataObject.DisplayResults + } else { + $jsonHealthChecker = $SaveDataObject | ConvertTo-Json -Depth 6 -ErrorAction Stop + } + + $outputXml.HealthCheckerExchangeServer = $jsonHealthChecker | ConvertFrom-Json -ErrorAction Stop + $outputXml | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop -Force + Write-Verbose "Successfully export out the data after the convert" + $dataExported = $true + } catch { + Write-Red "Failed to Export-Clixml. Unable to export the data." + } + } finally { + # This prevents the need to call Invoke-CatchActions + Invoke-ErrorCatchActionLoopFromIndex $currentErrors + } + return $dataExported + } + Write-Verbose "Calling: $($MyInvocation.MyCommand)" $paramWriteProgress = @{ Id = 1 @@ -96,10 +148,20 @@ function Get-HealthCheckerData { try { Invoke-SetOutputInstanceLocation -Server $serverName -FileName "HealthChecker" -IncludeServerName $true - Write-HostLog "Exchange Health Checker version $BuildVersion" + + if (-not $Script:VulnerabilityReport) { + # avoid having vulnerability report having a txt file with nothing in it besides the Exchange Health Checker Version + Write-HostLog "Exchange Health Checker version $BuildVersion" + } + + $HealthObject = $null $HealthObject = Get-HealthCheckerExchangeServer -ServerName $serverNameParam $HealthObject.OrganizationInformation = $organizationInformation + # If we successfully got the data, we want to export it out right away. + # This then allows if an exception does occur in the analysis stage, + # we then have the data output that is reproducing a problem in that section of code that we can debug. + $dataExported = ExportHealthCheckerXml -SaveDataObject $HealthObject -ProgressParams $paramWriteProgress $paramWriteProgress.Status = "Analyzing Data" Write-Progress @paramWriteProgress $analyzedResults = Invoke-AnalyzerEngine -HealthServerObject $HealthObject @@ -113,41 +175,21 @@ function Get-HealthCheckerData { } catch { Write-Red "Failed to Health Checker against $serverName" $failedServerList.Add($serverName) - # Try to handle the issue so we don't get a false positive report. - Invoke-CatchActions - continue - } - - $currentErrors = $Error.Count - $paramWriteProgress.Status = "Exporting Data" - Write-Progress @paramWriteProgress - - try { - $analyzedResults | Export-Clixml -Path $Script:OutXmlFullPath -Encoding UTF8 -Depth 2 -ErrorAction Stop - Write-Verbose "Successfully export out the data" - } catch { - 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." + if ($null -eq $HealthObject) { + # Try to handle the issue so we don't get a false positive report. + Invoke-CatchActions } + continue } finally { - # This prevents the need to call Invoke-CatchActions - Invoke-ErrorCatchActionLoopFromIndex $currentErrors + + if ($null -ne $analyzedResults) { + # Export out the analyzed data, as this is needed for Build HTML Report. + $dataExported = ExportHealthCheckerXml -SaveDataObject $analyzedResults -ProgressParams $paramWriteProgress + } # for now don't want to display that we output the information if ReturnDataCollectionOnly is false - if (-not $ReturnDataCollectionOnly) { + if ($dataExported -and -not $ReturnDataCollectionOnly) { Write-Grey("Output file written to {0}" -f $Script:OutputFullPath) Write-Grey("Exported Data Object Written to {0} " -f $Script:OutXmlFullPath) } diff --git a/Diagnostics/HealthChecker/Features/Invoke-VulnerabilityReport.ps1 b/Diagnostics/HealthChecker/Features/Invoke-VulnerabilityReport.ps1 index 874ad7d90f..dcce90b402 100644 --- a/Diagnostics/HealthChecker/Features/Invoke-VulnerabilityReport.ps1 +++ b/Diagnostics/HealthChecker/Features/Invoke-VulnerabilityReport.ps1 @@ -8,6 +8,18 @@ function Invoke-VulnerabilityReport { Write-Verbose "Calling: $($MyInvocation.MyCommand)" + $currentErrors = $Error.Count + + if ((-not $SkipVersionCheck) -and + (Test-ScriptVersion -AutoUpdate -VersionsUrl "https://aka.ms/HC-VersionsUrl")) { + Write-Yellow "Script was updated. Please rerun the command." + return + } else { + $Script:DisplayedScriptVersionAlready = $true + Write-Green "Exchange Health Checker version $BuildVersion" + } + + Invoke-ErrorCatchActionLoopFromIndex $currentErrors $stopWatch = [System.Diagnostics.Stopwatch]::StartNew() Set-ADServerSettings -ViewEntireForest $true $exchangeServers = @(Get-ExchangeServer) diff --git a/Diagnostics/HealthChecker/Helpers/Get-ErrorsThatOccurred.ps1 b/Diagnostics/HealthChecker/Helpers/Get-ErrorsThatOccurred.ps1 index 42a8560c76..64887bc25d 100644 --- a/Diagnostics/HealthChecker/Helpers/Get-ErrorsThatOccurred.ps1 +++ b/Diagnostics/HealthChecker/Helpers/Get-ErrorsThatOccurred.ps1 @@ -14,7 +14,8 @@ function Get-ErrorsThatOccurred { } if ($Error.Count -gt 0) { - Write-Grey(" "); Write-Grey(" ") + Write-Host "" + Write-Host "" function Write-Errors { Write-Verbose "`r`n`r`nErrors that occurred that wasn't handled" diff --git a/Diagnostics/HealthChecker/Helpers/Get-ExportedHealthCheckerFiles.ps1 b/Diagnostics/HealthChecker/Helpers/Get-ExportedHealthCheckerFiles.ps1 index 5ba351ab96..369a1a7c0d 100644 --- a/Diagnostics/HealthChecker/Helpers/Get-ExportedHealthCheckerFiles.ps1 +++ b/Diagnostics/HealthChecker/Helpers/Get-ExportedHealthCheckerFiles.ps1 @@ -38,17 +38,27 @@ function Get-ExportedHealthCheckerFiles { $groupResults | ForEach-Object { - if ($_.Count -gt 1) { - $groupData = $_.Group - $fileName = ($groupData | Sort-Object FileName -Descending | Select-Object -First 1).FileObject.VersionInfo.FileName - } else { - $fileName = ($_.Group).FileObject.VersionInfo.FileName - } + $sortedGroup = $_.Group | Sort-Object FileName -Descending + $index = 0 + $continueLoop = $true - $data = Import-Clixml -Path $fileName - if ($null -ne $data) { - $importedItems.Add($data) - } + do { + $fileName = $sortedGroup[$index].FileObject.VersionInfo.FileName + $data = Import-Clixml -Path $fileName + + if ($null -ne $data -and + $null -ne $data.HealthCheckerExchangeServer) { + Write-Verbose "For Server $($_.Group[0].ServerName) using file: $fileName" + $importedItems.Add($data) + $continueLoop = $false + } else { + $index++ + if ($index -ge $_.Count) { + $continueLoop = $false + Write-Red "Failed to find proper Health Checker data to import for server $($_.Group[0].ServerName)" + } + } + } while ($continueLoop) } } end { diff --git a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Main.Tests.ps1 b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Main.Tests.ps1 index 0630de6cf4..fe7881def0 100644 --- a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Main.Tests.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Main.Tests.ps1 @@ -177,7 +177,7 @@ Describe "Testing Health Checker by Mock Data Imports" { Mock Get-ExSetupFileVersionInfo { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\ExSetup1.xml" } Mock Get-WebSite -ParameterFilter { $Name -eq "Default Web Site" } -MockWith { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\IIS\GetWebSite_DefaultWebSite1.xml" } Mock Get-WebConfigFile -ParameterFilter { $PSPath -eq "IIS:\Sites\Default Web Site" } -MockWith { return [PSCustomObject]@{ FullName = "$Script:MockDataCollectionRoot\Exchange\IIS\DefaultWebSite_web2.config" } } - Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost2.config" -Raw } + Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost2.config" -Raw -Encoding UTF8 } Mock Get-DynamicDistributionGroup { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\GetDynamicDistributionGroupPfMailboxes1.xml" } Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Get TokenCacheModule version information" } -MockWith { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\IIS\GetVersionInformationCachToknPatched.xml" } diff --git a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios.Tests.ps1 b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios.Tests.ps1 index c0fc07e9cd..76630b7678 100644 --- a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios.Tests.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Testing Health Checker by Mock Data Imports" { # Needs to be like this to match the filter Mock Get-WebConfigFile -ParameterFilter { $PSPath -eq "IIS:\Sites\Exchange Back End/ecp" } -MockWith { return [PSCustomObject]@{ FullName = "$Script:MockDataCollectionRoot\Exchange\IIS\ClientAccess\ecp\web.config" } } Mock Get-WebConfigFile -ParameterFilter { $PSPath -eq "IIS:\Sites\Default Web Site/ecp" } -MockWith { return [PSCustomObject]@{ FullName = "$Script:MockDataCollectionRoot\Exchange\IIS\DefaultWebSite_web.config" } } - Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost1.config" -Raw } + Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost1.config" -Raw -Encoding UTF8 } Mock Get-ExchangeDiagnosticInfo { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\GetExchangeDiagnosticInfo1.xml" } Mock Get-IISModules { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\GetIISModulesNoTokenCacheModule.xml" } Mock Get-Service { @@ -221,9 +221,9 @@ Describe "Testing Health Checker by Mock Data Imports" { Mock Get-AcceptedDomain { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\GetAcceptedDomain_Bad.xml" } Mock Get-DnsClient { return Import-Clixml "$Script:MockDataCollectionRoot\OS\GetDnsClient1.xml" } Mock Get-ExSetupFileVersionInfo { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\ExSetup1.xml" } - Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost1.config" -Raw } - Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Runtime\1.0\noderunner.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\noderunner.exe1.config" -Raw } - Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\EdgeTransport.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\EdgeTransport.exe1.config" -Raw } + Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost1.config" -Raw -Encoding UTF8 } + Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Runtime\1.0\noderunner.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\noderunner.exe1.config" -Raw -Encoding UTF8 } + Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\EdgeTransport.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\EdgeTransport.exe1.config" -Raw -Encoding UTF8 } SetDefaultRunOfHealthChecker "Debug_Scenario2_Results.xml" } @@ -309,7 +309,7 @@ Describe "Testing Health Checker by Mock Data Imports" { Mock Get-WmiObjectHandler -ParameterFilter { $Class -eq "Win32_Processor" } ` -MockWith { return Import-Clixml "$Script:MockDataCollectionRoot\Hardware\Physical_Win32_Processor1.xml" } Mock Get-ExSetupFileVersionInfo { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\ExSetup1.xml" } - Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost2.config" -Raw } + Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost2.config" -Raw -Encoding UTF8 } SetDefaultRunOfHealthChecker "Debug_Scenario3_Physical_Results.xml" } diff --git a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios2.Tests.ps1 b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios2.Tests.ps1 index 56575d7b03..dc436b5f8e 100644 --- a/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios2.Tests.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthChecker.E19.Scenarios2.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Exchange 2019 Scenarios testing 2" { BeforeAll { Mock Get-WmiObjectHandler -ParameterFilter { $Class -eq "Win32_PageFileSetting" } ` -MockWith { return Import-Clixml "$Script:MockDataCollectionRoot\OS\Win32_PageFileWellConfigured.xml" } - Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\BadApplicationHost.config" -Raw } + Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\BadApplicationHost.config" -Raw -Encoding UTF8 } Mock Get-WebApplication -MockWith { throw "Error - Pester" } Mock Get-WebSite -ParameterFilter { $null -eq $Name } -MockWith { throw "Error - Pester" } Mock Get-WebSite -ParameterFilter { $Name -eq "Default Web Site" } -MockWith { throw "Error - Pester" } diff --git a/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 b/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 index d7d49662ef..38355629ae 100644 --- a/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 @@ -32,7 +32,7 @@ Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "T Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Get TokenCacheModule version information" } -MockWith { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\IIS\GetVersionInformationCachTokn.xml" } # Handle IIS collection of files -Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost.config" -Raw } +Mock Invoke-ScriptBlockHandler -ParameterFilter { $ScriptBlockDescription -eq "Getting applicationHost.config" } -MockWith { return Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\applicationHost.config" -Raw -Encoding UTF8 } Mock Get-CimInstance -ParameterFilter { $ClassName -eq "Win32_DeviceGuard" } -MockWith { return [PSCustomObject]@{ SecurityServicesRunning = @(0 , 0) } } @@ -47,10 +47,10 @@ Mock Test-Path -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Mock Test-Path -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\EdgeTransport.exe.config" } -MockWith { return $true } Mock Test-Path -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Runtime\1.0\noderunner.exe.config" } -MockWith { return $true } -Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\SharedWebConfig.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\DefaultWebSite_SharedWebConfig.config" -Raw } -Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\SharedWebConfig.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\ExchangeBackEnd_SharedWebConfig.config" -Raw } -Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\EdgeTransport.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\EdgeTransport.exe.config" -Raw } -Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Runtime\1.0\noderunner.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\noderunner.exe.config" -Raw } +Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\SharedWebConfig.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\DefaultWebSite_SharedWebConfig.config" -Raw -Encoding UTF8 } +Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\SharedWebConfig.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\IIS\ExchangeBackEnd_SharedWebConfig.config" -Raw -Encoding UTF8 } +Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\EdgeTransport.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\EdgeTransport.exe.config" -Raw -Encoding UTF8 } +Mock Get-Content -ParameterFilter { $Path -eq "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Runtime\1.0\noderunner.exe.config" } -MockWith { Get-Content "$Script:MockDataCollectionRoot\Exchange\noderunner.exe.config" -Raw -Encoding UTF8 } function Get-WebApplication { return Import-Clixml "$Script:MockDataCollectionRoot\Exchange\IIS\GetWebApplication.xml" } diff --git a/Shared/Get-FileContentInformation.ps1 b/Shared/Get-FileContentInformation.ps1 index 7e30bd4a30..a0c646f5bf 100644 --- a/Shared/Get-FileContentInformation.ps1 +++ b/Shared/Get-FileContentInformation.ps1 @@ -32,7 +32,7 @@ function Get-FileContentInformation { $present = (Test-Path $fileLocation) if ($present) { - $content = Get-Content $fileLocation -Raw + $content = Get-Content $fileLocation -Raw -Encoding UTF8 } else { $content = $null } diff --git a/Shared/IISFunctions/Get-ApplicationHostConfig.ps1 b/Shared/IISFunctions/Get-ApplicationHostConfig.ps1 index 7a207930fc..93f248b725 100644 --- a/Shared/IISFunctions/Get-ApplicationHostConfig.ps1 +++ b/Shared/IISFunctions/Get-ApplicationHostConfig.ps1 @@ -14,7 +14,7 @@ function Get-ApplicationHostConfig { $params = @{ ComputerName = $ComputerName ScriptBlockDescription = "Getting applicationHost.config" - ScriptBlock = { (Get-Content "$($env:WINDIR)\System32\inetSrv\config\applicationHost.config" -Raw).Trim() } + ScriptBlock = { (Get-Content "$($env:WINDIR)\System32\inetSrv\config\applicationHost.config" -Raw -Encoding UTF8).Trim() } CatchActionFunction = $CatchActionFunction }