AzStackHci.EnvironmentChecker.Reporting.psm1

<#
.SYNOPSIS
    Common Reporting functions across all modules/scenarios
.DESCRIPTION
    Logging, Reporting
.INPUTS
    Inputs (if any)
.OUTPUTS
    Output (if any)
.NOTES
    General notes
#>


function Set-AzStackHciOutputPath
{

    param ($Path, $Source='AzStackHciEnvironmentChecker/Diagnostic')
    if ([string]::IsNullOrEmpty($Path))
    {
        $Path = Join-Path -Path $HOME -ChildPath ".AzStackHci"
    }
    $Global:AzStackHciEnvironmentLogFile = Join-Path -Path $Path -ChildPath 'AzStackHciEnvironmentChecker.log'
    $Global:AzStackHciEnvironmentReport = Join-Path -Path $Path -ChildPath 'AzStackHciEnvironmentReport.json'
    $Global:AzStackHciEnvironmentReportXml = Join-Path -Path $Path -ChildPath 'AzStackHciEnvironmentReport.xml'
    Assert-EventLog -source $Source
    Set-AzStackHciIdentifier
}

Import-LocalizedData -BindingVariable lTxt -FileName AzStackHci.EnvironmentChecker.Strings.psd1

function Get-AzStackHciEnvProgress
{
    <#
    .SYNOPSIS
        Look for existing progress or create new progress.
    .DESCRIPTION
        Finds either the latest progress XML file or creates a new progress XML file
    .EXAMPLE
        PS C:\> <example usage>
        Explanation of what the example does
    .INPUTS
        Clean switch, in case the user wants to start fresh
        Path to search for progress run.
    .OUTPUTS
        PSCustomObject of progress.
    .NOTES
    #>

    param ([switch]$clean, $path = $PSScriptRoot)

    $latestReport = Get-Item -Path $Global:AzStackHciEnvironmentReportXml -ErrorAction SilentlyContinue
    try { $report = Import-Clixml $latestReport.FullName } catch {}
    if (-not $clean -and $latestReport -and $report)
    {
        Log-Info -Message ('Found existing report: {0}' -f $report.FilePath)
    }
    else
    {
        $hash = @{
            FilePath = $Global:AzStackHciEnvironmentReportXml
            Version  = $MyInvocation.MyCommand.Module.Version.ToString()
            Jobs     = @{}
        }
        $report = New-Object PSObject -Property $hash
        Log-Info -Message ('Creating new report {0}' -f $report.FilePath)
    }
    $report
}

function Write-AzStackHciEnvProgress
{
    <#
    .SYNOPSIS
        Write report output to JSON
    .DESCRIPTION
        After all processing, take results object and convert to JSON report.
        Any file already existing will be overwritten.
    .EXAMPLE
        Write-AzStackHciEnvProgress -report $report
        Writes $report to JSON file
    .INPUTS
        [psobject]
    .OUTPUTS
        XML file on disk (path on disk is expected to be embedded in psobject)
    .NOTES
        General notes
    #>

    param ([psobject]$report)

    try
    {
        $report | Export-Clixml -Depth 10 -Path $report.FilePath -Force
        Log-Info -Message ('AzStackHCI progress written: {0}' -f $report.FilePath)
    }
    Catch
    {
        Log-Info -Message ('Writing XML progress to disk error {0}' -f $_.exception.message) -Type Error
        throw $_.exception
    }
}

function Add-AzStackHciEnvJob
{
    <#
    .SYNOPSIS
        Adds a 'Job' to the progress object.
    .DESCRIPTION
        If a user runs the tool multiple time to check different assets
        e.g. Certificates on one execution and Registration details on the next execution
        Those executions are added to the progress for tracking purposes.
        Execution/Job details include:
            start time,
            parameters,
            parameterset (indicating what is being checked, certificates or Azure Accounts),
            Placeholders for EndTime and Duration (later filled in by Close-AzStackHciEnvJob)
    .EXAMPLE
        Add-AzStackHciEnvJob -report $report
        Adds execution job to progress object ($report)
    .INPUTS
        Report - psobject - containing all progress to date
    .OUTPUTS
        Report - psobject - updated with execution job log.
    .NOTES
        General notes
    #>

    param ($report)

    $allJobs = @{}
    $alljobs = $report.Jobs

    # Index for jobs must be a string for json conversion later
    if ($alljobs.Count)
    {
        $jobCount = ($alljobs.Count++).tostring()
    }
    else
    {
        $jobCount = '0'
    }

    # Record current job
    $currentJob = @{
        Index             = $jobCount
        StartTime         = (Get-Date -f 'yyyy/MM/dd HH:mm:ss')
        EndTime           = $null
        Duration          = $null
    }
    Log-Info -Message ('Adding current job to progress: {0}' -f $currentJob)
    # Add current job
    $allJobs += @{"$jobcount" = $currentJob }
    $report.Jobs = $allJobs
    $report
}

function Close-AzStackHciEnvJob
{
    <#
    .SYNOPSIS
        Writes endtime and duration for jobs
    .DESCRIPTION
        Find latest job entry and update time and calculates duration
        calls function to update xml on disk
        and updates and returns report object
    .EXAMPLE
        Close-AzStackHciEnvJob -report $report
    .INPUTS
        Report - psobject - containing all progress to date
    .OUTPUTS
        Report - psobject - updated with finished execution job log.
    .NOTES
        General notes
    #>

    param ($report)

    try
    {
        $latestJob = $report.jobs.Keys -match '[0-9]' | ForEach-Object { [int]$_ } | Sort-Object -Descending | Select-Object -First 1
        $report.jobs["$latestJob"].EndTime = (Get-Date -f 'yyyy/MM/dd HH:mm:ss')
        $duration = (([dateTime]$report.jobs["$latestJob"].EndTime) - ([dateTime]$report.jobs["$latestJob"].StartTime)).TotalSeconds
        $report.jobs["$latestJob"].Duration = $duration
        Log-Info -Message ('Updating current job to progress with endTime: {0} and duration {1}' -f $report.jobs["$latestJob"].EndTime, $duration)
    }
    Catch
    {
        Log-Info -Message ('Updating current job to progress failed with exception: {0}' -f $_.exception) -Type Error
    }
    Write-AzStackHciEnvProgress -report $report
    $report
}

function Write-AzStackHciEnvReport
{
    <#
    .SYNOPSIS
        Writes progress to disk in JSON format
    .DESCRIPTION
        Write progress object to disk in JSON format, overwriting as neccessary.
        The resulting blob is intended to be a portable record of what has been checked
        including the results of that check
    .EXAMPLE
        Write-AzStackHciEnvReport -report $report
    .INPUTS
        Report - psobject - containing all progress to date
    .OUTPUTS
        JSON - file - named AzStackEnvReport.json
    .NOTES
        General notes
    #>

    param ([psobject]$report)
    try
    {
        ConvertTo-Json -InputObject $report -Depth 8 -WarningAction SilentlyContinue | Out-File $AzStackHciEnvironmentReport -Force -Encoding UTF8
        Log-Info -Message ('JSON report written to {0}' -f $AzStackHciEnvironmentReport)
    }
    catch
    {
        Log-Info -Message ('Writing JSON report failed:' -f $_.exception.message) -Type Error
        throw $_.exception
    }
}

function Log-Info
{
    <#
    .SYNOPSIS
        Write verbose logging to disk
    .DESCRIPTION
        Formats and writes verbose logging to disk under scriptroot. Log type (or severity) is essentially cosmetic
        to the verbose log file, no action should be inferred, such as termination of the script.
    .EXAMPLE
        Write-AzStackHciEnvironmentLog -Message ('Script messaging include data {0}' -f $data) -Type 'Info|Warning|Error' -Function 'FunctionName'
    .INPUTS
        Message - a string of the body of the log entry
        Type - a cosmetic type or severity for the message, must be info, warning or error
        Function - ideally the name of the function or the script writing the log entry.
    .OUTPUTS
        Appends Log entry to AzStackHciEnvironmentChecker.log under the script root.
    .NOTES
        General notes
    #>

    [cmdletbinding()]
    param(
        [string]
        $Message,

        [ValidateSet('INFO', 'INFORMATIONAL', 'WARNING', 'CRITICAL', 'ERROR', 'SUCCESS')]
        [string]
        $Type = 'INFORMATIONAL',

        [ValidateNotNullOrEmpty()]
        [string]$Function = ((Get-PSCallStack)[0].Command),

        [switch]$ConsoleOut,

        [switch]$Telemetry
    )
    $Message = RunMask $Message
    if ($ConsoleOut)
    {
        #if ($PSEdition -eq 'desktop')
        if ($true)
        {
            switch -wildcard ($function)
            {
                '*-AzStackHciEnvironment*' { $foregroundcolor = 'DarkYellow' }
                default { $foregroundcolor = "White" }
            }
            switch ($Type)
            {
                'SUCCESS' { $foregroundcolor = 'Green' }
                'WARNING' { $foregroundcolor = 'Yellow' }
                'CRITICAL' { $foregroundcolor = 'Red' }
                'ERROR' { $foregroundcolor = 'Red' }
                default { $foregroundcolor = "White" }
            }
            Write-Host $message -ForegroundColor $foregroundcolor
        }
        else
        {
            Write-Host $message
        }
    }
    else
    {
        Write-Verbose $message
    }

    if (-not [string]::IsNullOrEmpty($message))
    {
        # Log to ETW
        if ($Telemetry)
        {
            $source = "AzStackHciEnvironmentChecker/Telemetry"
            $EventId = 17201
        }
        else
        {
            $source = "AzStackHciEnvironmentChecker/Operational"
            $EventId = 17203
        }
        $logName = 'AzStackHciEnvironmentChecker'
        $EventType = switch ($Type)
        {
            "ERROR" { "Error" }
            "CRITICAL" { "Error" }
            "WARNING" { 'Warning' }
            "SUCCESS" { "Information" }
            "INFORMATIONAL" { "Information" }
            Default { "Information" }
        }

        # Only write telemetry or non-info entries to the eventlog to save time and noise.
        if ($Telemetry -or $EventType -ne "Information")
        {
            Write-ETWLog -Source $Source -logName $logName -Message $Message -EventType $EventType -EventId $EventId
        }
        # Log to file
        $entry = "[{0}] [{1}] [{2}] {3}" -f ([datetime]::now).tostring(), $type.ToUpper(), $function, ($Message -replace "`n|`t", "")

        # If the log file path doesnt exist, create it
        if ([string]::IsNullOrEmpty($AzStackHciEnvironmentLogFile))
        {
            Set-AzStackHciOutputPath
        }
        if (-not (Test-Path $AzStackHciEnvironmentLogFile))
        {
            New-Item -Path $AzStackHciEnvironmentLogFile -Force | Out-Null
        }
        $retries = 3
        for ($i = 1; $i -le $retries; $i++) {
            try {
                $entry | Out-File -FilePath $AzStackHciEnvironmentLogFile -Append -Force -Encoding UTF8
                $writeFailed = $false
                break
            }
            catch {
                $writeFailed = "Log-info $i/$retries failed: $($_.ToString())"
                start-sleep -Seconds 5
            }
        }
        if ($writeFailed)
        {
            throw $writeFailed
        }
    }
}

function RunMask
{
    [cmdletbinding()]
    [OutputType([string])]
    Param (
        [Parameter(ValueFromPipeline = $True)]
        [string]
        $in
    )
    Begin {}
    Process
    {
        try
        {
            <#$in | Get-PIIMask | Get-GuidMask#>
            $in | Get-GuidMask
        }
        catch
        {
            $_.exception
        }
    }
    End {}
}

function Get-PIIMask
{
    [cmdletbinding()]
    [OutputType([string])]
    Param (
        [Parameter(ValueFromPipeline = $True)]
        [string]
        $in
    )
    Begin
    {
        $pii = $($ENV:USERDNSDOMAIN), $($ENV:COMPUTERNAME), $($ENV:USERNAME), $($ENV:USERDOMAIN) | ForEach-Object {
            if ($null -ne $PSITEM)
            {
                $PSITEM
            }
        }
        $r = $pii -join '|'
    }
    Process
    {
        try
        {
            return [regex]::replace($in, $r, "[*redacted*]")
        }
        catch
        {
            $_.exception
        }
    }
    End {}
}

function Get-GuidMask
{
    [OutputType([string])]
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $True)]
        [String]
        $guid
    )
    Begin
    {
        $r = [regex]::new("(-([a-fA-F0-9]{4}-){3})")

    }
    Process
    {
        try
        {
            return [regex]::replace($guid, $r, "-xxxx-xxxx-xxxx-")
        }
        catch
        {
            $_.exception
        }
    }
    End {}
}

function Write-AzStackHciHeader
{
    <#
    .SYNOPSIS
        Write invocation and system information into log and writes cmdlet name and version to screen.
    #>

    param (
        [Parameter()]
        [System.Management.Automation.InvocationInfo]
        $invocation,

        [psobject]
        $params,

        [switch]
        $PassThru
    )
    try
    {
        $paramToString = (($params | Protect-SensitiveProperties).GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join ';'
        $cmdLetName = Get-CmdletName
        $cmdletVersion = (Get-Command $cmdletName -ErrorAction SilentlyContinue).version.tostring()
        Log-Info -Message ''
        Log-Info -Message ('{0} v{1} started.' -f `
                $cmdLetName, $cmdletVersion) `
            -ConsoleOut:(-not $PassThru)

        Log-Info -Telemetry -Message ('{0} started version: {1} with parameters: {2}. Id:{3}' `
                -f $cmdLetName, (Get-Module AzStackHci.EnvironmentChecker).Version.ToString(), $paramToString, $ENV:EnvChkrId)

        Log-Info -Message ('OSVersion: {0} PSVersion: {1} PSEdition: {2} Security Protocol: {3} Lanaguage Mode: {4}' -f `
                [environment]::OSVersion.Version.tostring(), $PSVersionTable.PSVersion.tostring(), $PSEdition, [Net.ServicePointManager]::SecurityProtocol, $ExecutionContext.SessionState.LanguageMode)
        Write-PsSessionInfo -params $params
    }
    catch
    {
        if (-not $PassThru)
        {
            Log-Info ("Unable to write header to screen. Error: {0}" -f $_.exception.message)
        }
    }
}

function Write-AzStackHciFooter
{
    <#
    .SYNOPSIS
        Writes report, log and cmdlet to screen.
    #>

    param (
        [Parameter()]
        [System.Management.Automation.InvocationInfo]
        $invocation,

        [System.Management.Automation.ErrorRecord]
        $Exception,

        [switch]
        $PassThru
    )

    Log-Info -Message ("`nLog location: $AzStackHciEnvironmentLogFile") -ConsoleOut:(-not $PassThru)
    Log-Info -Message ("Report location: $AzStackHciEnvironmentReport") -ConsoleOut:(-not $PassThru)
    Log-Info -Message ("Use -Passthru parameter to return results as a PSObject.") -ConsoleOut:(-not $PassThru)
    if ($Exception)
    {
        Log-Info -Message ("{0} failed." -f (Get-CmdletName)) -ConsoleOut:(-not $PassThru) -Type Error
        Log-Info -Message ("{0} failed. Id:{1}. Exeception: {2}" -f (Get-CmdletName),$ENV:EnvChkrId,$Exception) -Type Error -Telemetry
    }
    else
    {
        Log-Info -Message ("{0} completed. Id:{1} " -f (Get-CmdletName),$ENV:EnvChkrId) -Telemetry
    }
}

function Get-CmdletName
{
    try
    {
        foreach ($c in (Get-PSCallStack).Command)
        {
            $functionCalled = Select-String -InputObject $c -Pattern "Invoke-AzStackHci(.*)Validation"
            if ($functionCalled)
            {
                 break
            }
        }
        $functionCalled
    }
    catch
    {
        throw "Hci Validation"
    }
}

function Write-AzStackHciResult
{
    <#
    .SYNOPSIS
        Displays results to screen
    .DESCRIPTION
        Displays test results to screen, highlighting failed tests.
    #>

    param (
        [Parameter()]
        [string]
        $Title,

        [Parameter()]
        [psobject]
        $result,

        $seperator = ' -> ',

        [switch]
        $Expand,

        [switch]
        $ShowFailedOnly
    )

    try
    {
        if (-not $result)
        {
            throw "Results missing. Ensure tests ran successfully."
        }
        Log-Info ("`n{0}:" -f $Title) -ConsoleOut


        foreach ($r in ($result | Sort-Object Status, Title, Description))
        {
            if ($r.status -ne 'SUCCESS' -or $Expand)
            {
                Write-StatusSymbol -Status $r.Status -Severity $r.Severity
                Write-Host " " -NoNewline
                Write-Host @expandDownSymbol
                Write-Host " " -NoNewline
                if ($r.status -ne 'SUCCESS')
                {
                    switch ($r.Severity)
                    {
                        Critical { Write-Host @needsRemediation }
                        Warning { Write-Host @needsAttention }
                        Informational { Write-Host @forInformation }
                        Default { Write-Host @Critical }
                    }
                }
                Write-Host " " -NoNewline
                Write-Host ($r.TargetResourceType + " - " + $r.Title + " " + $r.Description)
                foreach ($detail in ($r.AdditionalData | Sort-Object Status -Descending))
                {
                    if ($ShowFailedOnly -and $detail.Status -eq 'SUCCESS')
                    {
                        continue
                    }
                    else
                    {
                        Write-Host " " -NoNewline
                        Write-StatusSymbol -Status $detail.Status -Severity $r.Severity
                        Write-Host " " -NoNewline
                        Write-Host " " -NoNewline
                        Write-Host ("{0}{1}{2}" -f $detail.Source, $seperator, $detail.Resource)
                    }
                }
                if ($detail.Status -ne 'SUCCESS')
                {
                    Write-Host " " -NoNewline
                    Write-Host @helpSymbol
                    Write-Host (" Help URL: {0}" -f $r.Remediation)
                    Write-Host ""
                }
            }
            else
            {
                if (-not $ShowFailedOnly)
                {
                    Write-Host @expandOutSymbol
                    Write-Host " " -NoNewline
                    Write-Host @greenTickSymbol
                    Write-Host " " -NoNewline
                    Write-Host @isHealthy
                    Write-Host " " -NoNewline
                    Write-Host ($r.TargetResourceType + " " + $r.Title + " " + $r.Description)
                }
            }
        }
    }
    catch
    {
        Log-Info "Unable to write results. Error: $($_.exception.message)" -Type Warning
    }
}

function Write-ETWLog
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [string]
        $source = 'AzStackHciEnvironmentChecker/Diagnostic',

        [Parameter()]
        [string]
        $logName = 'AzStackHciEnvironmentChecker',

        [Parameter(Mandatory = $true)]
        [string]
        $Message,

        [Parameter()]
        [string]
        $EventId = 0,

        [Parameter()]
        [string]
        $EventType = 'Information'
    )
    try
    {
        Write-EventLog -LogName $LogName -Source $Source -EntryType $EventType -Message $Message -EventId $EventId
    }
    catch
    {
        throw "Creating event log failed. Error $($_.exception.message)"
    }
}

function Assert-EventLog
{
    param (
        [Parameter()]
        [string]
        $source = 'AzStackHciEnvironmentChecker/Diagnostic'
    )
    try
    {
        $eventLog = Get-EventLog -LogName AzStackHciEnvironmentChecker -Source $Source -ErrorAction SilentlyContinue
    }
    catch {}
    # Try to create the log
    if (-not $eventLog)
    {
        New-AzStackHciEnvironmentCheckerLog
    }
}

function Write-ETWResult
{
    <#
    .SYNOPSIS
        Write result to telemetry channel
    #>

    [CmdletBinding()]
    param (
        [Parameter()]
        [psobject]
        $Result
    )

    try {
        $source = 'AzStackHciEnvironmentChecker/Telemetry'
        if (![string]::IsNullOrEmpty($ENV:EnvChkrId))
        {
            $Result | Add-Member -MemberType NoteProperty -Name 'HealthCheckSource' -Value $ENV:EnvChkrId -Force -ErrorAction SilentlyContinue
        }
        $Message = $Result | ConvertTo-Json -Depth 5
        $EventId = 17205
        $EventType = if ($Result.Status -ne 'SUCCESS') { 'WARNING' } else { 'Information' }
        Write-ETWLog -Source $Source -EventType $EventType -Message $Message -EventId $EventId

    }
    catch {
        Log-Info "Failed to write result to telemetry channel. Error: $($_.Exception.message)" -Type Warning
    }
}

function Get-AzStackHciEnvironmentCheckerEvents
{
    <#
    .SYNOPSIS
        Retrieve AzStackHCI Environment Checker events from event log
    .EXAMPLE
        Get-AzStackHciEnvironmentCheckerEvents -Verbose
        Retrieve AzStackHCI Environment Checker events from event log
    .EXAMPLE
        $results = Get-AzStackHciEnvironmentCheckerEvents | ? EventId -eq 17205 | Select -last 1 | Select -expand Message | Convertfrom-Json
        Write-AzStackHciResult -result $results
        Get last result and write to screen
    #>


    [CmdletBinding()]
    param (
        [Parameter()]
        [ValidateSet('Operational', 'Diagnostic', 'Telemetry')]
        [string]
        $Source
    )
    try
    {
        $sourceFilter = switch ($source)
        {
            Operational { "AzStackHciEnvironmentChecker/Operational" }
            Diagnostic { "AzStackHciEnvironmentChecker/Diagnostic" }
            Telemetry { "AzStackHciEnvironmentChecker/Telemetry" }
            Default { "*" }
        }
        try
        {
            Get-EventLog -LogName AzStackHciEnvironmentChecker -Source $SourceFilter
        }
        catch {}
    }
    catch
    {
        throw "Failed to retrieve AzStackHCI environment checker logs. Error: $($_.exception.message)"
    }
}

function New-AzStackHciEnvironmentCheckerLog
{
    try
    {
        $scriptBlock = {
            $logName = 'AzStackHciEnvironmentChecker'
            $sources = @('AzStackHciEnvironmentChecker/Operational', 'AzStackHciEnvironmentChecker/Diagnostic', 'AzStackHciEnvironmentChecker/Telemetry', 'AzStackHciEnvironmentChecker/RemoteSupport', 'AzStackHciEnvironmentChecker/StandaloneObservability')
            foreach ($source in $sources)
            {
                New-EventLog -LogName $logName -Source $Source -ErrorAction SilentlyContinue
                Limit-EventLog -LogName $logName -MaximumSize 250MB
                Write-EventLog -Message ('Initializing log provider {0}' -f $source) -EventId 0 -EntryType Information -Source $source -LogName $logName -ErrorAction Stop
            }
        }

        if (Test-Elevation)
        {
            Invoke-Command -ScriptBlock $scriptBlock
        }
        else
        {
            $psProcess = if (Join-Path -Path $PSHOME -ChildPath powershell.exe -Resolve -ErrorAction SilentlyContinue)
            {
                Join-Path -Path $PSHOME -ChildPath powershell.exe
            }
            elseif (Join-Path -Path $PSHOME -ChildPath pwsh.exe -Resolve -ErrorAction SilentlyContinue)
            {
                Join-Path -Path $PSHOME -ChildPath pwsh.exe
            }
            else
            {
                throw "Cannot find powershell process. Please run powershell elevated and run the following command: 'New-EventLog -LogName $logName -Source $sourceName'"
            }
            Write-Warning "We need to run an elevated process to register our event log. `nPlease continue and accept the UAC prompt to continue. `nAlternatively, run: `nNew-EventLog -LogName $logName -Source $source `nmanually and restart this command."
            if (Grant-UACConcent)
            {
                Start-Process $psProcess -Verb Runas -ArgumentList "-command (Invoke-Command -ScriptBlock {$scriptBlock})" -Wait
            }
            else
            {
                throw "Unable to elevate and register event log provider."
            }
        }
    }
    catch
    {
        throw "Failed to create Environment Checker log. Error: $($_.Exception.Message)"
    }
}

function Remove-AzStackHciEnvironmentCheckerEventLog
{
    <#
    .SYNOPSIS
        Remove AzStackHCI Environment Checker event log
    .EXAMPLE
        Remove-AzStackHciEnvironmentCheckerEventLog -Verbose
        Remove AzStackHCI Environment Checker event log
    #>

    [cmdletbinding()]
    param()
    Remove-EventLog -LogName "AzStackHciEnvironmentChecker"
}


function Grant-UACConcent
{
    $concentAnswered = $false
    $concent = $false
    while ($false -eq $concentAnswered)
    {
        $promptResponse = Read-Host -Prompt "Register the event log. (Y/N)"
        if ($promptResponse -imatch '^y$|^yes$')
        {
            $concentAnswered = $true
            $concent = $true
        }
        elseif ($promptResponse -imatch '^n$|^no$')
        {
            $concentAnswered = $true
            $concent = $false
        }
        else
        {
            Write-Warning "Unexpected response"
        }
    }
    return $concent
}

function Write-Summary
{
    param ($result, $property1, $property2, $property3, $seperator = '->')
    try
    {
        $summary = Get-Summary @PSBoundParameters

        # Write percentage
        Write-Host "`nSummary"
        Write-Host $lTxt.Summary
        if (-not ([string]::IsNullOrEmpty($summary.FailedResourceCritical)))
        {
            Write-Host " " -NoNewline
            Write-StatusSymbol -status 'FAILURE' -Severity Critical
            Write-Host (" {0} Critical Issue(s)" -f @($summary.FailedResourceCritical).Count)
        }

        if (-not ([string]::IsNullOrEmpty($summary.FailedResourceWarning)))
        {
            Write-Host " " -NoNewline
            Write-StatusSymbol -status 'FAILURE' -Severity Warning
            Write-Host (" {0} Warning Issue(s)" -f @($summary.FailedResourceWarning).Count)
        }

        if (-not ([string]::IsNullOrEmpty($summary.FailedResourceInformational)))
        {
            Write-Host " " -NoNewline
            Write-StatusSymbol -status 'FAILURE' -Severity Informational
            Write-Host (" {0} Informational Issue(s)" -f @($summary.FailedResourceInformational).Count)
        }

        if ($Summary.successCount -gt 0)
        {
            Write-Host " " -NoNewline
            Write-StatusSymbol -status 'SUCCESS'
            Write-Host (" {0} successes" -f ($Summary.successCount))
        }

        <#Write-Host @expandDownSymbol
        Write-Host " " -NoNewline
        switch ($Severity)
        {
            'CRITICAL' { Write-Host @redCrossSymbol }
            'WARNING' { Write-Host @warningSymbol }
            Default { Write-Host @redCrossSymbol }
        }#>

        #Write-Host (" {0} / {1} ({2}%)" -f $summary.SuccessCount, $Result.AdditionalData.Resource.Count, $summary.SuccessPercentage)

        # Write issues by severity
        foreach ($severity in 'CRITICAL', 'WARNING', 'INFORMATIONAL')
        {
            $SeverityProp = "FailedResource{0}" -f $severity
            $failedResources = $summary.$SeverityProp | Sort-Object | Get-Unique

            if ($failedResources -gt 0)
            {
                Write-Host ""
                Write-Severity -severity $Severity
                Write-Host ""
                #Write-Host "`n$Severity Issues:"
                $failedResources | Sort-Object | Get-Unique | ForEach-Object {
                    Write-Host " " -NoNewline
                    switch ($Severity)
                    {
                        'CRITICAL' { Write-Host @redCrossSymbol }
                        'WARNING' { Write-Host @warningSymbol }
                        Default { Write-Host @redCrossSymbol }
                    }
                    Write-Host " $PSITEM"
                }
            }
        }

        if ($Summary.HelpLinks)
        {
            Write-Host "`nRemediation: "
            $Summary.HelpLinks | ForEach-Object {
                Write-Host " " -NoNewline
                Write-Host @helpSymbol
                Write-Host " $PSITEM"
            }
        }

        if (-not $summary.FailedResourceCritical -and -not $summary.FailedResourceWarning -and -not $summary.FailedResourceInformational)
        {
            Write-Host "`nSummary"
            Write-Host @expandOutSymbol
            Write-Host " " -NoNewline
            Write-Host @greenTickSymbol
            Write-Host (" {0} / {1} ({2}%) resources test successfully." -f $summary.SuccessCount, $Result.AdditionalData.Resource.Count, $summary.SuccessPercentage)
        }
    }
    catch
    {
        Log-Info -Message "Summary failed. $($_.Exception.Message)" -ConsoleOut -Type Warning
    }
}

function Get-Summary
{
    param ($result, $property1, $property2, $property3, $seperator = '->')

    try
    {
        if (-not $result)
        {
            throw "Unable to write summary. Check tests run successfully."
        }
        [array]$success = $result | Select-Object -ExpandProperty AdditionalData | Where-Object Status -EQ 'SUCCESS'
        [array]$HelpLinks = $result | Where-Object Status -NE 'SUCCESS' | Select-Object -ExpandProperty Remediation | Sort-Object | Get-Unique
        [array]$nonSuccess = $result | Select-Object -ExpandProperty AdditionalData | Where-Object Status -NE 'SUCCESS'
        [array]$nonSuccessCritical = $result | Where-Object Severity -EQ Critical | Select-Object -ExpandProperty AdditionalData | Where-Object Status -NE 'SUCCESS'
        [array]$nonSuccessWarning = $result | Where-Object Severity -EQ Warning | Select-Object -ExpandProperty AdditionalData | Where-Object Status -NE 'SUCCESS'
        [array]$nonSuccessInformational = $result | Where-Object Severity -EQ Informational | Select-Object -ExpandProperty AdditionalData | Where-Object Status -NE 'SUCCESS'

        $successPercentage = if ($success.count -gt 0)
        {
            [Math]::Round(($success.Count / $result.AdditionalData.Resource.count) * 100)
        }
        else
        {
            0
        }

        $sourceDestsb = {
            if ([string]::IsNullOrEmpty($_.$property2) -and [string]::IsNullOrEmpty($_.$property3))
            {
                "{0}" -f $_.$property1
            }
            elseif ([string]::IsNullOrEmpty($_.$property3))
            {
                "{0}{1}{2}" -f $_.$property1, $seperator, $_.$property2
            }
            else
            {
                "{0}{1}{2}({3})" -f $_.$property1, $seperator, $_.$property2, $_.$property3
            }
        }
        $FailedResourceCritical = $nonSuccessCritical |
        Select-Object @{ label = 'SourceDest'; Expression = $sourceDestsb } -ErrorAction SilentlyContinue |
        Select-Object -ExpandProperty SourceDest |
        Sort-Object |
        Get-Unique

        $FailedResourceWarning = $nonSuccessWarning |
        Select-Object @{ label = 'SourceDest'; Expression = $sourceDestsb } -ErrorAction SilentlyContinue |
        Select-Object -ExpandProperty SourceDest |
        Sort-Object |
        Get-Unique

        $FailedResourceInformational = $nonSuccessInformational |
        Select-Object @{ label = 'SourceDest'; Expression = $sourceDestsb } -ErrorAction SilentlyContinue |
        Select-Object -ExpandProperty SourceDest |
        Sort-Object |
        Get-Unique

        $summary = New-Object -Type PsObject -Property @{
            successCount                = $success.Count
            nonSuccessCount             = $nonSuccess.Count
            successPercentage           = $successPercentage
            HelpLinks                   = $HelpLinks
            FailedResourceCritical      = $FailedResourceCritical
            FailedResourceWarning       = $FailedResourceWarning
            FailedResourceInformational = $FailedResourceInformational
        }
        return $summary
    }
    catch
    {
        throw "Unable to calculate summary. Error $($_.exception.message)"
    }
}

# Symbols
$global:greenTickSymbol = @{
    Object          = [Char]0x2713     #8730
    ForegroundColor = 'Green'
    NoNewLine       = $true
}
$global:redCrossSymbol = @{
    Object          = [Char]0x2622 #0x00D7
    ForegroundColor = 'Red'
    NoNewLine       = $true
}

$global:WarningSymbol = @{
    Object          = [char]0x26A0
    ForegroundColor = 'Yellow'
    NoNewLine       = $true
}

$global:bulletSymbol = @{
    Object    = [Char]0x25BA
    NoNewLine = $true
}

# Text
$global:needsAttention = @{
    object          = $lTxt.NeedsAttention;
    ForegroundColor = 'Yellow'
    NoNewLine       = $true
}

$global:needsRemediation = @{
    object          = $lTxt.NeedsRemediation;
    ForegroundColor = 'Red'
    NoNewLine       = $true
}

$global:ForInformation = @{
    object    = $lTxt.ForInformation;
    NoNewLine = $true
}

$global:expandDownSymbol = @{
    object    = [Char]0x25BC # expand down
    NoNewLine = $true
}

$global:expandOutSymbol = @{
    object    = [Char]0x25BA # expand out
    NoNewLine = $true
}

$global:helpSymbol = @{
    object    = [char]0x270E   #0x263C # sunshine
    NoNewLine = $true
    #ForegroundColor = 'Yellow'
}

$global:Critical = @{
    object          = $lTxt.Critical;
    ForegroundColor = 'Red'
    NoNewLine       = $true
}

$global:Warning = @{
    object          = $lTxt.Warning;
    ForegroundColor = 'Yellow'
    NoNewLine       = $true
}

$global:Information = @{
    object    = $lTxt.Informational;
    NoNewLine = $true
}

$global:isHealthy = @{
    object    = $lTxt.Healthy
    NoNewLine = $true
}

function Write-StatusSymbol
{
    param ($status, $severity)
    switch ($status)
    {
        "SUCCESS" { Write-Host @greenTickSymbol }
        "FAILURE"
        {
            switch ($Severity)
            {
                'CRITICAL' { Write-Host @redCrossSymbol }
                'WARNING' { Write-Host @warningSymbol }
                Default { Write-Host @redCrossSymbol }
            }
        }
        Default { Write-Host @bulletSymbol }
    }
}

function Write-Severity
{
    param ($severity)
    switch ($severity)
    {
        'CRITICAL' { Write-Host @needsRemediation }
        'WARNING' { Write-Host @needsAttention }
        'INFORMATIONAL' { Write-Host @ForInformation }
        Default { Write-Host @Critical }
    }
}

function Set-AzStackHciIdentifier
{
    $ENV:EnvChkrId = $null
    if ([string]::IsNullOrEmpty($ENV:EnvChkrOp))
    {
        $ENV:EnvChkrOp = 'Manual'
    }
    $validatorCmd = Get-CmdletName
    if(-not [string]::IsNullOrWhiteSpace($validatorCmd))
    {
        $ENV:EnvChkrId = "{0}\{1}\{2}" -f $ENV:EnvChkrOp, $validatorCmd.matches.groups[1], (([system.guid]::newguid()) -split '-' | Select-Object -first 1)
    }
}

function Write-PsSessionInfo
{
    <#
    .SYNOPSIS
        Write some pertainent information to the log about any PsSessions passed
    #>

    [CmdletBinding()]
    param (
        $params
    )
    try {
        if ($params['PsSession'])
        {
            foreach ($session in $params['PsSession'])
            {
                Log-Info -Message ("PsSession info: {0}, {1}, {2}, {3}, {4}, {5}" -f $session.ComputerName, $session.Name, $session.Id, $session.Runspace.ConnectionInfo.credential.username, $session.Runspace.SessionStateProxy.LanguageMode, $session.Runspace.ConnectionInfo.AuthenticationMechanism)
            }
        }
        else
        {
            Log-Info -Message "No PsSession info to write"
        }
    }
    catch
    {
        Log-Info -Message "Failed to write PsSession info: $($_.exception.message)"
    }
}

function Log-CimData
{

    [CmdletBinding()]
    param (
        $cimData,
        [array]$properties
    )
    try {
        # Use properties provided or all properties if none provided
        $selectProperties = @()
        $selectProperties += if ($null -eq $Properties)
        {
            "*"
        }
        else {
            foreach ($property in $Properties)
            {
                if ($property -is [hashtable])
                {
                    $property.Keys
                }
                else
                {
                    $property
                }
            }
        }

        # For each server log the cimdata
        foreach ($serverName in ($cimData.CimSystemProperties.ServerName | Sort-Object | Get-Unique))
        {
            $sData = $cimData | Where-Object {$_.CimSystemProperties.ServerName -eq $ServerName }
            [string]$className = $sData.CimClass.CimClassName | Sort-Object | Get-Unique
            Log-Info ("{0} cim instance data for {1}" -f $className, $serverName)
            $sData | Select-Object -Property $selectProperties | ConvertTo-Csv | Out-String -Stream | ForEach-Object {
                if (![string]::IsNullOrEmpty($_))
                {
                    Log-Info $_
                }
            }
        }
    }
    catch
    {
        Log-Info "Failed to write cimdata to log file. Error: $($_.Exception.Message)" -Type Error
    }
}

function New-AzStackHciResultObject
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [String]
        $Name,

        [Parameter()]
        [String]
        $DisplayName,

        [Parameter()]
        [String]
        $Title,

        [Parameter()]
        [Hashtable]
        $Tags,

        [Parameter()]
        [String]
        $Status,

        [Parameter()]
        [String]
        $Severity,

        [Parameter()]
        [String]
        $Description,

        [Parameter()]
        [String]
        $Remediation,

        [Parameter()]
        [String]
        $TargetResourceID,

        [Parameter()]
        [String]
        $TargetResourceName,

        [Parameter()]
        [String]
        $TargetResourceType,

        [Parameter()]
        [datetime]
        $Timestamp,

        [Parameter()]
        [Hashtable]
        $AdditionalData,

        [Parameter()]
        [string]
        $HealthCheckSource
    )
    # load the assembly as an array of bytes to avoid locking the dll.
    $bytes = [system.io.file]::ReadAllBytes("$PsScriptRoot\Schema\Microsoft.EnvironmentReadiness.Validator.Client.dll")
    $assembly = [Reflection.Assembly]::Load($bytes)
    $type = $assembly.GetType("Microsoft.EnvironmentReadiness.Client.Models.EnvironmentReadinessTestResult")
    $resultObj = New-Object -TypeName $type.FullName
    # Set properties from PSBoundParameters
    foreach ($param in $PSBoundParameters.Keys)
    {
        if ($PSBoundParameters[$param])
        {
            if ($PSBoundParameters[$param] -is [System.Collections.Hashtable])
            {
                $resultObj.$param = ConvertTo-Dictionary -hashTable $PSBoundParameters[$param]
            }
            else {
                $resultObj.$param = $PSBoundParameters[$param]
            }
        }
    }
    return $resultObj
}

# Convert hashtable to dictionary
function ConvertTo-Dictionary {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [hashtable]$hashTable
    )
    begin {
        $dictionary = New-Object 'system.collections.generic.dictionary[string,string]'
    }
    process {
        foreach ($key in $hashTable.Keys) {
            if ([string]::IsNullOrEmpty($hashTable[$key]))
            {
                $value = ""
            }
            else {
                $value = $hashTable[$key]
            }
            $dictionary.Add($key, $value)
        }
    }
    end {
        return ,$dictionary
    }
}

# function to get psobject from pipeline and redact sensitive property values
function Protect-SensitiveProperties
{
    param (
        [Parameter(ValueFromPipeline = $true)]
        [psObject]
        $params
    )
    BEGIN
    {
        $array = @()
    }
    PROCESS
    {
        try
        {
            $ret = @{}
            foreach($key in $_.Keys)
            {
                # Redact sensitive parameters
                if($Key -match "ArmAccessToken|Account|PsSession")
                {
                    $ret += @{$Key = '[redacted]'}
                }
                else
                {
                    $ret += @{$Key = $_[$Key]}
                }
            }
            $array += $ret
        }
        catch
        {
            Log-Info "Error occurred trying to remove sensitive parameters. Error: $($_.Exception.Message)" -Type ERROR
        }
    }
    END
    {
        return $array
    }
}

Export-ModuleMember -function Add-AzStackHciEnvJob
Export-ModuleMember -function Close-AzStackHciEnvJob
Export-ModuleMember -function Get-AzStackHciEnvironmentCheckerEvents
Export-ModuleMember -function Get-AzStackHciEnvProgress
Export-ModuleMember -function Log-Info
Export-ModuleMember -function Set-AzStackHciOutputPath
Export-ModuleMember -function Write-AzStackHciEnvReport
Export-ModuleMember -function Write-AzStackHciFooter
Export-ModuleMember -function Write-AzStackHciHeader
Export-ModuleMember -function Write-AzStackHciResult
Export-ModuleMember -function Write-ETWLog
Export-ModuleMember -function Write-ETWResult
Export-ModuleMember -function Write-Summary
Export-ModuleMember -function Log-CimData
Export-ModuleMember -function New-AzStackHciResultObject
# SIG # Begin signature block
# MIIoKgYJKoZIhvcNAQcCoIIoGzCCKBcCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCAcLVvLxMn/ZqGi
# 3MlCUDT/RB7wzd6Pl8mDEQM2S13zTqCCDXYwggX0MIID3KADAgECAhMzAAADrzBA
# DkyjTQVBAAAAAAOvMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24xKDAmBgNVBAMTH01pY3Jvc29mdCBDb2RlIFNpZ25p
# bmcgUENBIDIwMTEwHhcNMjMxMTE2MTkwOTAwWhcNMjQxMTE0MTkwOTAwWjB0MQsw
# CQYDVQQGEwJVU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