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
        }

        $cluster = Get-Cluster
        $clusterNodesCount = (Get-ClusterNode -cluster $cluster).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
# MIInvwYJKoZIhvcNAQcCoIInsDCCJ6wCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCALw42TScXFJ7xH
# ZvDELeOHvVIPPWO/34sXbcHBBg8ppaCCDXYwggX0MIID3KADAgECAhMzAAADrzBA
# DkyjTQVBAAAAAAOvMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRt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