AzStackHciUpgrade/AzStackHci.Upgrade.Helpers.psm1

Import-LocalizedData -BindingVariable luTxt -FileName AzStackHci.Upgrade.Strings.psd1
Import-Module $PSScriptRoot\..\AzStackHciHardware\AzStackHci.Hardware.Helpers.psm1 -Force -DisableNameChecking -Global


function Test-23H2
{
    <#
    .SYNOPSIS
        Test Windows OS is 23H2
    .DESCRIPTION
        Test Windows OS is 23H2
    .EXAMPLE
        PS C:\> Test-23H2
        Test Windows OS is 23H2 on localhost.
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        Import-Module "$PsScriptRoot\..\AzStackHciSoftware\AzStackHci.Software.Helpers.psm1" -Force
        # 23H2 greater and equal 8B (do 6B for now)
        $instanceResults = Test-OSVersion -PsSession $PsSession -MinimumVersion '10.0.25398.887'
        foreach ($instanceResult in $instanceResults)
        {
            $instanceResult.Name = 'AzStackHci_Upgrade_23H2'
            $instanceResult.Title = 'Test Windows OS is 23H2'
            $instanceResult.DisplayName = 'Test Windows OS is 23H2'
            $instanceResult.Description = 'Checking Windows OS is 23H2'
            $instanceResult.Tags = @{}
            $instanceResult.Severity = 'CRITICAL'
            $instanceResult.Remediation = 'https://learn.microsoft.com/en-us/azure-stack/hci/deploy/deployment-tool-install-os'
            $instanceResult.TargetResourceID = $instanceResult.TargetResourceName
            $instanceResult.TargetResourceType = 'OS'
            $instanceResult.HealthCheckSource = $ENV:EnvChkrId
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }

}

function Test-HciCluster
{
    <#
    .SYNOPSIS
        Test all nodes are part of the same cluster, nodes are up and cluster is not stretched
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            $clusterName = ""
            try {
                $clusterName = Get-Cluster | Select-Object -Expand Name
                # omitting -Cluster as this requires CredSSP
                $clusterNodes = Get-ClusterNode
                $clusterFaultDomainSiteName = Get-ClusterFaultDomain -Type Site | Select-Object -Expand Name
            }
            catch{}
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                Cluster = $clusterName
                ClusterNodes = $clusterNodes
                ClusterFaultDomain = $clusterFaultDomainSiteName
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $instanceResults = @()
        # Check cluster exists
        foreach ($output in $remoteOutput)
        {
            if ([string]::IsNullOrEmpty($output.Cluster))
            {
                $status = 'FAILURE'
                $detail = $luTxt.NoClusterFound -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }
            else
            {
                $status = 'SUCCESS'
                $detail = $luTxt.ClusterFound -f $output.ComputerName, $output.Cluster
                Log-Info $detail
            }

            $params = @{
                Name               = 'AzStackHci_Upgrade_Cluster_Exists'
                Title              = 'Test Cluster Exists'
                DisplayName        = 'Test Cluster Exists'
                Severity           = 'CRITICAL'
                Description        = 'Checking Cluster is installed'
                Tags               = @{}
                Remediation        = 'https://learn.microsoft.com/en-us/azure-stack/hci/deploy/deployment-tool-install-os'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Cluster'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Cluster'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }

        # Check all nodes part of same cluster
        # ensure all cluster nodes are part of the same cluster
        if (($remoteOutput.Cluster | Sort-Object | Get-Unique).Count -eq 1)
        {
            $status = 'SUCCESS'
            Log-Info $detail
        }
        else
        {
            $status = 'FAILURE'
            Log-Info $detail -Type CRITICAL
        }

        $params = @{
            Name               = 'AzStackHci_Upgrade_AllNodesInSameCluster'
            Title              = 'Test All Nodes in Same Cluster'
            DisplayName        = 'Test All Nodes in Same Cluster'
            Severity           = 'CRITICAL'
            Description        = 'Checking all nodes are part of the same cluster'
            Tags               = @{}
            Remediation        = 'https://aka.ms/UpgradeRequirements'
            TargetResourceID   = 'Cluster'
            TargetResourceName = 'Cluster'
            TargetResourceType = 'Cluster'
            Timestamp          = [datetime]::UtcNow
            Status             = $status
            AdditionalData     = @{
                Source    = 'Cluster'
                Resource  = 'Cluster'
                Detail    = $detail
                Status    = $status
                TimeStamp = [datetime]::UtcNow
            }
            HealthCheckSource  = $ENV:EnvChkrId
        }

        $instanceResults += New-AzStackHciResultObject @params

        # Return if there is a failure at this point
        if ('FAILURE' -in $instanceResults.Status)
        {
            return $instanceResults
        }
        else
        {
            # Test all nodes are up
            Log-Info "Cluster Nodes:"
            Log-Info ($remoteOutput.ClusterNodes | Out-String)
            foreach ($node in $remoteOutput[0].ClusterNodes)
            {
                if ($node.State -ne 'Up')
                {
                    $status = 'FAILURE'
                    $detail = "Node $($node.Name) is not in 'Up' state."
                    Log-Info $detail -Type CRITICAL
                }
                else
                {
                    $status = 'SUCCESS'
                    $detail = "Node $($node.Name) is in 'Up' state."
                    Log-Info $detail
                }
                $params = @{
                    Name               = 'AzStackHci_Upgrade_ClusterNodeUp'
                    Title              = 'Test Cluster Node is up'
                    DisplayName        = "Test Cluster Node is up $($node.Name)"
                    Severity           = 'CRITICAL'
                    Description        = 'Checking cluster node is up'
                    Tags               = @{}
                    Remediation        = 'https://aka.ms/UpgradeRequirements'
                    TargetResourceID   = $node.Name
                    TargetResourceName = $node.Name
                    TargetResourceType = 'ClusterNode'
                    Timestamp          = [datetime]::UtcNow
                    Status             = $status
                    AdditionalData     = @{
                        Source    = 'Cluster'
                        Resource  = 'ClusterNode'
                        Detail    = $detail
                        Status    = $status
                        TimeStamp = [datetime]::UtcNow
                    }
                    HealthCheckSource  = $ENV:EnvChkrId
                }
                $instanceResults += New-AzStackHciResultObject @params
            }
        }

        # Make sure cluster is not stretched

        if (($output.ClusterFaultDomain | Sort-Object | Get-Unique).Count -gt 1)
        {
            $status = 'FAILURE'
            $detail = $luTxt.StretchedClusterEnabled -f $output.Cluster
            Log-Info $detail -Type CRITICAL
        }
        else
        {
            $status = 'SUCCESS'
            $detail = $luTxt.StretchedClusterNotEnabled -f $output.Cluster
            Log-Info $detail
        }

        $params = @{
            Name               = 'AzStackHci_Upgrade_StretchedCluster'
            Title              = 'Test Stretched Cluster'
            DisplayName        = 'Test Stretched Cluster'
            Severity           = 'CRITICAL'
            Description        = 'Checking Stretched Cluster is enabled'
            Tags               = @{}
            Remediation        = 'https://aka.ms/UpgradeRequirements'
            TargetResourceID   = $output.ComputerName
            TargetResourceName = $output.ComputerName
            TargetResourceType = 'Cluster'
            Timestamp          = [datetime]::UtcNow
            Status             = $status
            AdditionalData     = @{
                Source    = $output.ComputerName
                Resource  = 'Stretched Cluster'
                Detail    = $detail
                Status    = $status
                TimeStamp = [datetime]::UtcNow
            }
            HealthCheckSource  = $ENV:EnvChkrId
        }
        $instanceResults += New-AzStackHciResultObject @params
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-RequiredWindowsFeature
{
    <#
    .SYNOPSIS
        Test if the required Windows feature is installed
    .DESCRIPTION
        Test if the required Windows feature is installed
    .EXAMPLE
        PS C:\> Test-RequiredWindowsFeature
        Test if the required Windows feature is installed on localhost.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            # Can be dedup with windowsOptionalFeatureToCheck
            $windowsFeatureTocheck =  @(
                "Failover-Clustering",
                "NetworkATC",
                "RSAT-AD-Powershell",
                "RSAT-Hyper-V-Tools",
                "Data-Center-Bridging",
                "NetworkVirtualization",
                "RSAT-AD-AdminCenter"
            )
            $windowsOptionalFeatureToCheck = @(
                "Server-Core",
                "ServerManager-Core-RSAT",
                "ServerManager-Core-RSAT-Role-Tools",
                "ServerManager-Core-RSAT-Feature-Tools",
                "DataCenterBridging-LLDP-Tools",
                "Microsoft-Hyper-V",
                "Microsoft-Hyper-V-Offline",
                "Microsoft-Hyper-V-Online",
                "RSAT-Hyper-V-Tools-Feature",
                "Microsoft-Hyper-V-Management-PowerShell",
                "NetworkVirtualization",
                "RSAT-AD-Tools-Feature",
                "RSAT-ADDS-Tools-Feature",
                "DirectoryServices-DomainController-Tools",
                "ActiveDirectory-PowerShell",
                "DirectoryServices-AdministrativeCenter",
                "DNS-Server-Tools",
                "EnhancedStorage",
                "WCF-Services45",
                "WCF-TCP-PortSharing45",
                "NetworkController",
                "NetFx4ServerFeatures",
                "NetFx4",
                "MicrosoftWindowsPowerShellRoot",
                "MicrosoftWindowsPowerShell",
                "Server-Psh-Cmdlets",
                "KeyDistributionService-PSH-Cmdlets",
                "TlsSessionTicketKey-PSH-Cmdlets",
                "Tpm-PSH-Cmdlets",
                "FSRM-Infrastructure",
                "ServerCore-WOW64",
                "SmbDirect",
                "FailoverCluster-AdminPak",
                "Windows-Defender",
                "SMBBW",
                "FailoverCluster-FullServer",
                "FailoverCluster-PowerShell",
                "Microsoft-Windows-GroupPolicy-ServerAdminTools-Update",
                "DataCenterBridging",
                "BitLocker",
                "FileServerVSSAgent",
                "FileAndStorage-Services",
                "Storage-Services",
                "File-Services",
                "CoreFileServer",
                "SystemDataArchiver",
                "ServerCoreFonts-NonCritical-Fonts-MinConsoleFonts",
                "ServerCoreFonts-NonCritical-Fonts-BitmapFonts",
                "ServerCoreFonts-NonCritical-Fonts-TrueType",
                "ServerCoreFonts-NonCritical-Fonts-UAPFonts",
                "ServerCoreFonts-NonCritical-Fonts-Support",
                "ServerCore-Drivers-General",
                "ServerCore-Drivers-General-WOW64",
                "NetworkATC"
            )
            $windowsFeatureNotInstalled = @()
            foreach ($featureName in $windowsFeatureToCheck)
            {
                if (-not (Get-WindowsFeature -Name $featureName | Where-Object InstallState -eq Installed))
                {
                    $windowsFeatureNotInstalled += $featureName
                }
            }
            $windowsOptionalFeatureNotEnabled = @()
            foreach ($featureName in $windowsOptionalFeatureToCheck)
            {
                if (-not (Get-WindowsOptionalFeature -Online -FeatureName $featureName | Where-Object State -eq Enabled))
                {
                    $windowsOptionalFeatureNotEnabled += $featureName
                }
            }
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                list = $windowsFeatureNotInstalled + $windowsOptionalFeatureNotEnabled
                result = ($windowsFeatureNotInstalled.Count -eq 0) -and ($windowsOptionalFeatureNotEnabled.Count -eq 0)
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.RequiredWindowsFeatureEnabled -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $featureList = ($output.list) -join ', '
                $detail = $luTxt.RequiredWindowsFeatureNotEnabled -f $featureList, $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }

            $params = @{
                Name               = 'AzStackHci_Required_Windows_Features'
                Title              = 'Test Required Windows features'
                DisplayName        = 'Test Required Windows features'
                Severity           = 'Critical'
                Description        = 'Checks that all nodes have the required Windows features installed'
                Tags               = @{}
                Remediation        = "https://aka.ms/UpgradeRequirements"
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Feature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Required Windows features '
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }

}

function Test-NetworkAtcIntents
{
    <#
    .SYNOPSIS
        Test the required Network ATC intents are present and in heathy state
    .DESCRIPTION
        Test the required Network ATC intents are present and in heathy state
    .EXAMPLE
        PS C:\> Test-NetworkAtcIntents
        Test the required Network ATC intents are present and in heathy state.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            $networkATC = [bool](Get-WindowsFeature -Name NetworkATC | Where-Object InstallState -eq 'Installed')
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $networkATC
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $hasError = $false
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.NetworkAtcEnabled -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $hasError = $true
                $detail = $luTxt.NetworkAtcNotEnabled -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }

            $params = @{
                Name               = 'AzStackHci_Upgrade_Test_NetworkATCFeature_Installed'
                Title              = 'Test Network ATC feature is installed on the node'
                DisplayName        = 'Test Network ATC feature is installed on the node'
                Severity           = 'CRITICAL'
                Description        = 'Checking Network ATC feature is enabled on the node'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeNetworkATC'
                TargetResourceID   = 'NetworkAtcFeature'
                TargetResourceName = 'NetworkAtcFeature'
                TargetResourceType = 'NetworkAtcFeature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Network ATC'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }

        # If there is a node that doesn't have Network ATC enabled, then the cluster won't have proper network ATC intents configured. So no need to check further.
        if ($hasError)
        {
            return $instanceResults
        }

        # Check if the Network ATC service is running on the nodes
        $remoteOutput = @()
        $sb = {
            $atcService = Get-Service NetworkATC -ErrorAction SilentlyContinue
            $atcServiceRunning = $atcService -and $atcService.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $atcServiceRunning
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.NetworkAtcServiceRunning -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.NetworkAtcServiceNotRunning -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }

            $params = @{
                Name               = 'AzStackHci_Upgrade_Test_NetworkATCService_Running'
                Title              = 'Test NetworkATC service is running on the node'
                DisplayName        = 'Test NetworkATC service is running on the node'
                Severity           = 'CRITICAL'
                Description        = 'Checking NetworkATC service is running on the node'
                Tags               = @{}
                Remediation        = 'Make sure NetworkAtc service is running on the node. If not, start the service.'
                TargetResourceID   = 'NetworkAtcService'
                TargetResourceName = 'NetworkAtcService'
                TargetResourceType = 'NetworkAtcService'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Network ATC'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }

        # Check if the required Network ATC intents are present
        $remoteOutput = @()
        $sb = {
            $intents = Get-NetIntent -ErrorAction SilentlyContinue
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $intents
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $clusterNodesCount = (Get-ClusterNode).Count
        foreach ($output in $remoteOutput)
        {
            if ($null -eq $output.result)
            {
                $status = 'FAILURE'
                $detail = $luTxt.NetworkAtcIntentsNotPresent -f $output.ComputerName
                Log-Info $detail -Type CRITICAL

                $params = @{
                    Name               = 'AzStackHci_Upgrade_Test_NetworkATCIntents_Present'
                    Title              = 'Test NetworkATC intents are present on the node'
                    DisplayName        = 'Test NetworkATC intents are present on the node'
                    Severity           = 'CRITICAL'
                    Description        = 'Checking NetworkATC intents are present on the node'
                    Tags               = @{}
                    Remediation        = 'Make sure NetworkATC intents are properly configured on the node.'
                    TargetResourceID   = 'NetworkAtcIntents'
                    TargetResourceName = 'NetworkAtcIntents'
                    TargetResourceType = 'NetworkAtcIntents'
                    Timestamp          = [datetime]::UtcNow
                    Status             = $status
                    AdditionalData     = @{
                        Source    = $output.ComputerName
                        Resource  = 'Network ATC'
                        Detail    = $detail
                        Status    = $status
                        TimeStamp = [datetime]::UtcNow
                    }
                    HealthCheckSource  = $ENV:EnvChkrId
                }
                $instanceResults += New-AzStackHciResultObject @params
            }
            else
            {
                $outputResultString = $output.result | Out-String
                log-info "Get-NetIntent returned from node $($output.ComputerName) : $outputResultString"

                $isManagementIntentPresent = $output.result | Where-Object { $_.IsManagementIntentSet -eq $true }
                $isStorageIntentPresent = $output.result | Where-Object { $_.IsStorageIntentSet -eq $true }

                if (-not $isManagementIntentPresent)
                {
                    $status = 'FAILURE'
                    $detail = $luTxt.NetworkAtcManagementIntentNotPresent -f $output.ComputerName
                    Log-Info $detail -Type CRITICAL

                    $params = @{
                        Name               = 'AzStackHci_Upgrade_Test_NetworkATCManagementIntent_Present'
                        Title              = 'Test NetworkATC management intent is present on the node'
                        DisplayName        = 'Test NetworkATC management intent is present on the node'
                        Severity           = 'CRITICAL'
                        Description        = 'Checking NetworkATC management intent is present on the node'
                        Tags               = @{}
                        Remediation        = 'Make sure NetworkATC management intent is properly configured on the node.'
                        TargetResourceID   = 'NetworkAtcManagementIntent'
                        TargetResourceName = 'NetworkAtcManagementIntent'
                        TargetResourceType = 'NetworkAtcManagementIntent'
                        Timestamp          = [datetime]::UtcNow
                        Status             = $status
                        AdditionalData     = @{
                            Source    = $output.ComputerName
                            Resource  = 'Network ATC'
                            Detail    = $detail
                            Status    = $status
                            TimeStamp = [datetime]::UtcNow
                        }
                        HealthCheckSource  = $ENV:EnvChkrId
                    }
                    $instanceResults += New-AzStackHciResultObject @params
                }
                elseif (-not $isStorageIntentPresent -and $clusterNodesCount -gt 1) {
                    $status = 'FAILURE'
                    $detail = $luTxt.NetworkAtcStorageIntentNotPresent -f $output.ComputerName
                    Log-Info $detail -Type CRITICAL

                    $params = @{
                        Name               = 'AzStackHci_Upgrade_Test_NetworkATCStorageIntent_Present'
                        Title              = 'Test NetworkATC storage intent is present on the node'
                        DisplayName        = 'Test NetworkATC storage intent is present on the node'
                        Severity           = 'CRITICAL'
                        Description        = 'Checking NetworkATC storage intent is present on the node'
                        Tags               = @{}
                        Remediation        = 'Make sure NetworkATC storage intent is properly configured on the node if it is multi-node HCI system.'
                        TargetResourceID   = 'NetworkAtcStorageIntent'
                        TargetResourceName = 'NetworkAtcStorageIntent'
                        TargetResourceType = 'NetworkAtcStorageIntent'
                        Timestamp          = [datetime]::UtcNow
                        Status             = $status
                        AdditionalData     = @{
                            Source    = $output.ComputerName
                            Resource  = 'Network ATC'
                            Detail    = $detail
                            Status    = $status
                            TimeStamp = [datetime]::UtcNow
                        }
                        HealthCheckSource  = $ENV:EnvChkrId
                    }
                    $instanceResults += New-AzStackHciResultObject @params
                }
                else
                {
                    $status = 'SUCCESS'
                    $detail = $luTxt.NetworkAtcRequiredIntentsArePresent -f $output.ComputerName
                    Log-Info $detail

                    $params = @{
                        Name               = 'AzStackHci_Upgrade_Test_NetworkATCRequiredIntents_Present'
                        Title              = 'Test NetworkATC required intents are present on the node'
                        DisplayName        = 'Test NetworkATC required intents are present on the node'
                        Severity           = 'CRITICAL'
                        Description        = 'Checking NetworkATC required intents are present on the node'
                        Tags               = @{}
                        Remediation        = 'https://aka.ms/UpgradeNetworkATC'
                        TargetResourceID   = 'NetworkAtcIntents'
                        TargetResourceName = 'NetworkAtcIntents'
                        TargetResourceType = 'NetworkAtcIntents'
                        Timestamp          = [datetime]::UtcNow
                        Status             = $status
                        AdditionalData     = @{
                            Source    = $output.ComputerName
                            Resource  = 'Network ATC'
                            Detail    = $detail
                            Status    = $status
                            TimeStamp = [datetime]::UtcNow
                        }
                        HealthCheckSource  = $ENV:EnvChkrId
                    }
                    $instanceResults += New-AzStackHciResultObject @params
                }
            }
        }

        # check if the intents on the nodes are in healthy state
        $remoteOutput = @()
        $sb = {
            $intentStatus = Get-NetIntentStatus -ErrorAction SilentlyContinue
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $intentStatus
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        foreach ($output in $remoteOutput)
        {
            $resultString = $output.result | Out-String
            log-info "Get-NetIntentStatus returned from node $($output.ComputerName) : $resultString"

            $failedIntents = $output.result | Where-Object { $_.ConfigurationStatus -ne 'Success' -or $_.ProvisioningStatus -ne 'Completed' }

            if ($null -ne $failedIntents)
            {
                $status = 'FAILURE'
                $detail = $luTxt.NetworkAtcIntentsStatusNotHealthy -f $output.ComputerName
                Log-Info $detail -Type CRITICAL

                $params = @{
                    Name               = "AzStackHci_Upgrade_Test_NetworkATCIntent_HealthyState"
                    Title              = "Test NetworkAtc intent configuration and provisioning status"
                    DisplayName        = "Test NetworkAtc intent configuration and provisioning status"
                    Severity           = 'CRITICAL'
                    Description        = "Checking Test NetworkAtc intent configuration and provisioning status"
                    Tags               = @{}
                    Remediation        = "Use Get-NetIntentStatus cmdlet to check the status of the intent and take necessary action to fix the issue."
                    TargetResourceID   = "NetworkAtcIntents"
                    TargetResourceName = "NetworkAtcIntents"
                    TargetResourceType = "NetworkAtcIntents"
                    Timestamp          = [datetime]::UtcNow
                    Status             = $status
                    AdditionalData     = @{
                        Source    = $output.ComputerName
                        Resource  = "NetworkAtcIntents"
                        Detail    = $detail
                        Status    = $status
                        TimeStamp = [datetime]::UtcNow
                    }
                    HealthCheckSource  = $ENV:EnvChkrId
                }
                $instanceResults += New-AzStackHciResultObject @params
            }
            elseif ($null -eq $output.result)
            {
                $status = 'FAILURE'
                $detail = $luTxt.NetworkAtcIntentsStatusNull -f $output.ComputerName
                Log-Info $detail -Type CRITICAL

                $params = @{
                    Name               = "AzStackHci_Upgrade_Test_NetworkATCIntent_StatusNull"
                    Title              = "Test NetworkAtc intent configuration and provisioning status"
                    DisplayName        = "Test NetworkAtc intent configuration and provisioning status"
                    Severity           = 'CRITICAL'
                    Description        = "Checking Test NetworkAtc intent configuration and provisioning status"
                    Tags               = @{}
                    Remediation        = "Use Get-NetIntentStatus cmdlet to check the status of the intents and take necessary action to fix the issue."
                    TargetResourceID   = "NetworkAtcIntents"
                    TargetResourceName = "NetworkAtcIntents"
                    TargetResourceType = "NetworkAtcIntents"
                    Timestamp          = [datetime]::UtcNow
                    Status             = $status
                    AdditionalData     = @{
                        Source    = $output.ComputerName
                        Resource  = "NetworkAtcIntents"
                        Detail    = $detail
                        Status    = $status
                        TimeStamp = [datetime]::UtcNow
                    }
                    HealthCheckSource  = $ENV:EnvChkrId
                }
                $instanceResults += New-AzStackHciResultObject @params
            }
            else
            {
                $status = 'SUCCESS'
                $detail = $luTxt.NetworkAtcIntentsHealthy -f $output.ComputerName
                Log-Info $detail

                $params = @{
                    Name               = "AzStackHci_Upgrade_Test_NetworkATCIntent_HealthyState"
                    Title              = "Test NetworkAtc intent configuration and provisioning status"
                    DisplayName        = "Test NetworkAtc intent configuration and provisioning status"
                    Severity           = 'CRITICAL'
                    Description        = "Checking Test NetworkAtc intent configuration and provisioning status"
                    Tags               = @{}
                    Remediation        = 'https://aka.ms/UpgradeNetworkATC'
                    TargetResourceID   = "NetworkAtcIntents"
                    TargetResourceName = "NetworkAtcIntents"
                    TargetResourceType = "NetworkAtcIntents"
                    Timestamp          = [datetime]::UtcNow
                    Status             = $status
                    AdditionalData     = @{
                        Source    = $output.ComputerName
                        Resource  = "NetworkAtcIntents"
                        Detail    = $detail
                        Status    = $status
                        TimeStamp = [datetime]::UtcNow
                    }
                    HealthCheckSource  = $ENV:EnvChkrId
                }
                $instanceResults += New-AzStackHciResultObject @params
            }
        }

        return $instanceResults
    }
    catch
    {
        throw $_
    }

}

function Test-TPMHealth
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try {
        $results = @()
        $results += Test-TpmVersion -PsSession $PsSession
        $results += Test-TpmProperties -PsSession $PsSession
        $results += Test-TpmCertificates -PsSession $PsSession
        $results | % {
            $_.Name = $_.Name -replace 'Hardware','Upgrade'
            $_.Severity = 'WARNING'
        }
        return $results
    }
    catch {
        throw $_
    }
}

function Test-BitlockerSuspension
{
    <#
    .SYNOPSIS
        Test if bitlocker is enabled but not in suspended state.
    .DESCRIPTION
        Test if bitlocker is enabled but not in suspended state.
    .EXAMPLE
        PS C:\> function Test-BitlockerSuspension
        Test if bitlocker is enabled but not in suspended state for all volumes.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )

    $remoteOutput = @()
    try {

        $sb = {

            try {
                $volumes = $null

                try {
                    $volumes = Get-BitLockerVolume
                }
                catch {
                    # Return test result as True/Pass because we dont want to fail test if bitlocker feature is not available.
                    return New-Object PSObject -Property @{
                        ComputerName = $ENV:COMPUTERNAME
                        Details = "Could not fetch bitlocker volumes. Error: " + $_.Exception.Message
                        error = $_.Exception.Message
                        result = $true
                        isBitlockerFeatureInstalled = $false
                    }
                }

                $volumeDetails = ""
                $overallStatus = $true

                if($volumes)
                {
                    $criticalVolumes = $volumes |? {$_.KeyProtector.KeyProtectorType -contains "Tpm"}
                    foreach ($volume in $criticalVolumes) {
                        # Get volume information
                        $volumeInfo = Get-BitLockerVolume -MountPoint $volume.MountPoint
                        $volumeMountPoint = $volumeInfo.MountPoint
                        $volumeProtectionStatus = $volumeInfo.ProtectionStatus
                        $volumeType = $volumeInfo.VolumeType

                        # Check if BitLocker protection is enabled
                        if($volumeInfo.ProtectionStatus -eq "On")
                        {
                            $overallStatus = $false
                        }

                        $volumeDetails += "Volume with mount point: $volumeMountPoint and type : $volumeType has a protection status of $volumeProtectionStatus. `n"
                    }
                }
                else {
                    $volumeDetails = "No bitlocker volumes found."
                }
                return New-Object PSObject -Property @{
                    ComputerName = $ENV:COMPUTERNAME
                    Details = $volumeDetails
                    result = $overallStatus
                }
            }
            catch {
                return New-Object PSObject -Property @{
                    ComputerName = $ENV:COMPUTERNAME
                    Details = $volumeDetails + $_.Exception.Message
                    error = $_.Exception.Message
                    result = $false
                }
            }
        }

        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            Log-Info $output.Details

            if ($output.result -eq $true)
            {
                if(($output.isBitlockerFeatureInstalled -ne $null) -and ($output.isBitlockerFeatureInstalled -eq $false))
                {
                    $status = 'SUCCESS'
                    $detail = $luTxt.BitlockerFeatureNotInstalled -f $output.ComputerName
                    Log-Info $detail -Type CRITICAL
                }
                else
                {
                    $status = 'SUCCESS'
                    $detail = $luTxt.BitlockerEncryptedVolumesSuspended -f $output.ComputerName
                    Log-Info $detail
                }
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.BitlockerEncryptedVolumesNotSuspended -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }

            $params = @{
                Name               = 'AzStackHci_Upgrade_BitlockerSuspension'
                Title              = 'Test Bitlocker Suspension'
                DisplayName        = 'Test Bitlocker Suspension'
                Severity           = 'CRITICAL'
                Description        = 'Checking if any volumes have bitlocker suspended.'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeRequirements'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Security'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Bitlocker Suspension'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch {
        throw $_
    }
}

function Test-WdacEnablement
{
    <#
    .SYNOPSIS
        Test if WDAC is enabled
    .DESCRIPTION
        Test if WDAC is enabled
    .EXAMPLE
        PS C:\> function Test-WdacEnablement
        Test if WDAC is enabled on localhost.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            $cipFiles = Get-ChildItem -Path "$env:SystemRoot\System32\CodeIntegrity\CiPolicies\Active" -Filter *.cip
            if ($cipFiles.Count -gt 0)
            {
                # Refresh the current policy and check if audit mode is enabled from the lastest event
                Invoke-CimMethod -Namespace 'root\Microsoft\Windows\CI' -ClassName 'PS_UpdateAndCompareCIPolicy' -MethodName 'Update' -Arguments @{FilePath = $cipFiles[0].FullName} | Out-Null
                $events = Get-WinEvent -LogName "Microsoft-Windows-CodeIntegrity/Operational" -ErrorAction SilentlyContinue
                $targetEvent = $events | Where-Object { ($_.Id -in @('3099','3096')) -and ($_.Message -imatch $cipFiles[0].BaseName) } | Sort-Object TimeCreated -Descending | Select-Object -First 1
                $eventXml = [XML]$targetEvent.ToXml()
                $eventData = $eventXml.Event.EventData.Data
                $policyOptions = [System.Convert]::ToInt64($eventData[6].'#text', 16)
                # SYSTEM_INTEGRITY_POLICY_ENABLE_AUDIT_MODE 1 << 16 => 65536
                $policyResult = (($policyOptions -band 65536) -eq 0)
            }
            else
            {
                # No WDAC policy file found
                $policyResult = $false
            }
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $policyResult
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'FAILURE'
                $detail = $luTxt.WdacEnabled -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }
            else
            {
                $status = 'SUCCESS'
                $detail = $luTxt.WdacNotEnabled -f $output.ComputerName
                Log-Info $detail
            }
            $params = @{
                Name               = 'AzStackHci_Upgrade_WDACEnablement'
                Title              = 'Test WDAC Enablement'
                DisplayName        = 'Test WDAC Enablement'
                Severity           = 'CRITICAL'
                Description        = 'Checking if WDAC is enabled'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeRequirements'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Security'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'WDAC Enablement'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-AzureSupportedCloudType
{
     <#
    .SYNOPSIS
        Test if cluster is connected to Azure Public Cloud.
    .DESCRIPTION
        Upgrade is only supported for clusters connected to Azure Public Cloud.
    .EXAMPLE
        PS C:\> function Test-AzureSupportedCloudType
    .EXAMPLE
 
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )


    $sb= {
            try
                {
                    if(Test-Path -Path "C:\Program Files\AzureConnectedMachineAgent\azcmagent.exe")
                    {
                        $overallStatus = $true
                        $testDetails = ""
                        $arcAgentStatus = Invoke-Expression -Command "& 'C:\Program Files\AzureConnectedMachineAgent\azcmagent.exe' show -j"
                        # Parsing the status received from Arc agent
                        $arcAgentStatusParsed = $arcAgentStatus | ConvertFrom-Json

                        # Throw an error if the node is Arc enabled to any other cloud apart from Azure Public cloud.
                        # Other supported values which are not supported for Upgrade : AzureUSGovernment , AzureChinaCloud
                        if ([string]::IsNullOrEmpty($arcAgentStatusParsed.cloud))
                        {
                            $overallStatus = $false
                            $testDetails = "Unable to determine Azure cloud type. ARC Agent status read: [{0}]" -f $arcAgentStatus
                        }
                        elseif (($arcAgentStatusParsed.cloud -ne "AzureCloud"))
                        {
                            $overallStatus = $false
                            $testDetails = "{0}: Arc Agent is connected to {1}: cloud, which is not supported for upgrade." -f  $ENV:COMPUTERNAME,$arcAgentStatusParsed.cloud
                        }
                    }
                    else
                    {
                        $overallStatus = $false
                        $testDetails ="ARC agent installation cannot be found at : C:\Program Files\AzureConnectedMachineAgent\azcmagent.exe"
                    }
                    return New-Object PSObject -Property @{
                        ComputerName = $ENV:COMPUTERNAME
                        Details = $testDetails
                        result = $overallStatus
                        }
                }
                catch
                {
                    return New-Object PSObject -Property @{
                        ComputerName = $ENV:COMPUTERNAME
                        Details = $_.Exception.Message
                        result = $false
                    }
                }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }

        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            Log-Info $output.Details
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.CloudSupported -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.CloudNotSupported -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }

            $params = @{
                Name               = 'AzStackHci_Upgrade_SupportedCloud'
                Title              = 'Test Supported Cloud Type'
                DisplayName        = 'Test Supported Cloud Type'
                Severity           = 'CRITICAL'
                Description        = 'Checking if any node is connected to an unsupported cloud'
                Tags               = @{}
                Remediation        = 'https://learn.microsoft.com/en-us/azure-stack/hci/concepts/system-requirements-23h2'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Feature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'Azure Cloud'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults


}

function Test-AksHciInstallState
{
    <#
    .SYNOPSIS
        Test Windows Deduplication is enabled
    .DESCRIPTION
        Test Windows Deduplication is enabled
    .EXAMPLE
        PS C:\> Test-WindowsDeduplication
        Test if Windows Deduplication is enabled on localhost.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            Import-Module AksHci -ErrorAction SilentlyContinue
            $result = [bool](Get-Module AksHci)
            if($result)
            {
                try
                {
                    $installState = (Get-AksHciConfig).AksHci.installState -ne "NotInstalled"
                    if($installState) {
                        return New-Object PSObject -Property @{
                            ComputerName = $ENV:COMPUTERNAME
                            result = $false
                            error = "AksHci is installed"
                        }
                    }
                }
                catch
                {
                    #NOOP
                }
            }
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $true
                error = ""
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.AksHciNotInstalled -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.AksHciInstalled -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }
            $params = @{
                Name               = 'AzStackHci_Upgrade_AksHci'
                Title              = 'Test AKS HCI install state'
                DisplayName        = "Test AKS HCI install state on $($output.ComputerName)"
                Severity           = 'CRITICAL'
                Description        = 'Checking if AKS HCI is installed'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeRequirements'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Feature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'AKS HCI'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-MocInstallState
{
    <#
    .SYNOPSIS
        Test Windows Deduplication is enabled
    .DESCRIPTION
        Test Windows Deduplication is enabled
    .EXAMPLE
        PS C:\> Test-WindowsDeduplication
        Test if Windows Deduplication is enabled on localhost.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            Import-Module Moc -ErrorAction SilentlyContinue
            $result = [bool](Get-Module Moc)
            if($result)
            {
                try
                {
                    $installState = (Get-MocConfig).installState -ne "NotInstalled"
                    if($installState) {
                        return New-Object PSObject -Property @{
                            ComputerName = $ENV:COMPUTERNAME
                            result = $false
                            error = "Moc is installed"
                        }
                    }
                }
                catch
                {
                    #NOOP
                }
            }
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $true
                error = ""
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.MocNotInstalled -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.MocInstalled -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }
            $params = @{
                Name               = 'AzStackHci_Upgrade_Moc'
                Title              = 'Test MOC install state'
                DisplayName        = "Test MOC install state on $($output.ComputerName)"
                Severity           = 'CRITICAL'
                Description        = 'Checking if MOC is installed'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeRequirements'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Feature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'MOC'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-MocServicesInstallState
{
    <#
    .SYNOPSIS
        Test Windows Deduplication is enabled
    .DESCRIPTION
        Test Windows Deduplication is enabled
    .EXAMPLE
        PS C:\> Test-WindowsDeduplication
        Test if Windows Deduplication is enabled on localhost.
    .EXAMPLE
        PS C:\> $Credential = Get-Credential -Message "Credential for $RemoteSystem"
        PS C:\> $RemoteSystemSession = New-PSSession -Computer
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            $service = Get-Service -Name wssdcloudagent -ErrorAction SilentlyContinue
            if($null -ne $service)
            {
                return New-Object PSObject -Property @{
                    ComputerName = $ENV:COMPUTERNAME
                    result = $false
                    error = "wssdcloudagent service is running"
                }
            }
            $service = Get-Service -Name wssdagent -ErrorAction SilentlyContinue
            if($null -ne $service)
            {
                return New-Object PSObject -Property @{
                    ComputerName = $ENV:COMPUTERNAME
                    result = $false
                    error = "wssdagent service is running"
                }
            }
            $service = Get-Service -Name MocHostAgent -ErrorAction SilentlyContinue
            if($null -ne $service)
            {
                return New-Object PSObject -Property @{
                    ComputerName = $ENV:COMPUTERNAME
                    result = $false
                    error = "MocHostAgent service is running"
                }
            }
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                result = $true
                error = ""
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            if ($output.result)
            {
                $status = 'SUCCESS'
                $detail = $luTxt.MocServicesNotInstalled -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.MocServicesInstalled -f $output.ComputerName
                Log-Info $detail -Type CRITICAL
            }
            $params = @{
                Name               = 'AzStackHci_Upgrade_MocServices'
                Title              = 'Test MOC services running'
                DisplayName        = "Test MOC services running on $($output.ComputerName)"
                Severity           = 'CRITICAL'
                Description        = 'Checking MOC services running state'
                Tags               = @{}
                Remediation        = 'https://aka.ms/UpgradeRequirements'
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Feature'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = 'MOC services'
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-Language
{
    <#
    .SYNOPSIS
        Test if the language is English-US
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $false)]
        [System.Management.Automation.Runspaces.PSSession[]]
        $PsSession
    )
    try
    {
        $remoteOutput = @()
        $sb = {
            $lang = Get-WinUserLanguageList
            return New-Object PSObject -Property @{
                ComputerName = $ENV:COMPUTERNAME
                Language = $lang
            }
        }
        if ($PsSession)
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb -Session $PsSession
        }
        else
        {
            $remoteOutput += Invoke-Command -ScriptBlock $sb
        }
        $instanceResults = @()
        foreach ($output in $remoteOutput)
        {
            Log-Info "Langauges on $($output.ComputerName) :"
            Log-Info  ($output.Language | Out-String)
            if ($output.Language.LanguageTag -like 'en-*')
            {
                $status = 'SUCCESS'
                $detail = $luTxt.LanguageEnglishUS -f $output.ComputerName
                Log-Info $detail
            }
            else
            {
                $status = 'FAILURE'
                $detail = $luTxt.LanguageNotEnglishUS -f $output.ComputerName, $output.Language.LanguageTag
                Log-Info $detail -Type CRITICAL
            }
            $params = @{
                Name               = 'AzStackHci_Upgrade_Language'
                Title              = 'Test Language is English'
                DisplayName        = 'Test Language is English'
                Severity           = 'CRITICAL'
                Description        = 'Checking if the language is English'
                Tags               = @{}
                Remediation        = "https://aka.ms/UpgradeRequirements"
                TargetResourceID   = $output.ComputerName
                TargetResourceName = $output.ComputerName
                TargetResourceType = 'Language'
                Timestamp          = [datetime]::UtcNow
                Status             = $status
                AdditionalData     = @{
                    Source    = $output.ComputerName
                    Resource  = "Language: $($output.Language.LanguageTag)"
                    Detail    = $detail
                    Status    = $status
                    TimeStamp = [datetime]::UtcNow
                }
                HealthCheckSource  = $ENV:EnvChkrId
            }
            $instanceResults += New-AzStackHciResultObject @params
        }
        return $instanceResults
    }
    catch
    {
        throw $_
    }
}

function Test-Storage
{
    [CmdletBinding()]
    param ()
    try {
        $results = @()
        $poolConfigXml = [xml]'<StoragePool><Volumes><Volume Name="Infrastructure_1" Size="256GB" MinNodeCount="1" ></Volume></Volumes></StoragePool>'
        $results += Invoke-AzStackHciStorageValidation -PoolConfigXml $poolConfigXml -PassThru
        $results | % {
            $_.Name = $_.Name -replace 'AzStackHci_Storage','AzStackHci_Upgrade'
        }
        return $results
    }
    catch {
        throw $_
    }
}

Export-ModuleMember -Function Test-*
# SIG # Begin signature block
# MIInwgYJKoZIhvcNAQcCoIInszCCJ68CAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBpIiIROue6VCIw
# GzyxCJuNnZKmRkxGjTmLP2eHENPXa6CCDXYwggX0MIID3KADAgECAhMzAAADrzBA
# DkyjTQVBAAAAAAOvMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
#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