Obs/bin/ObsDep/content/Powershell/Roles/Common/RoleHelpers.psm1

<###################################################
 # #
 # Copyright (c) Microsoft. All rights reserved. #
 # #
 ##################################################>


Import-Module $PSScriptRoot\JustEnoughAdministrationHelpers.psm1 -DisableNameChecking -Verbose:$false | Out-Null
Import-Module NetworkControllerRESTWrappers -DisableNameChecking -Verbose:$false | Out-Null
Import-Module $PSScriptRoot\NetworkControllerWorkloadHelpers.psm1 -DisableNameChecking -Verbose:$false | Out-Null

# Below 4 modules will ues -ErrorAction SilentlyContinue as the import might happen at the dependency repo code and those might not package the CloudCommon modules.
# In such case, the functionnality is not impacted as CloudCommon is always copied into Windows PowerShell module at the beginning of action plan exectuion
Import-Module $PSScriptRoot\..\..\Common\Helpers.psm1 -DisableNameChecking -Verbose:$false -ErrorAction SilentlyContinue | Out-Null
Import-Module $PSScriptRoot\..\..\Common\NetworkHelpers.psm1 -DisableNameChecking -Verbose:$false -ErrorAction SilentlyContinue | Out-Null
Import-Module $PSScriptRoot\..\..\Common\StorageHelpers.psm1 -DisableNameChecking -Verbose:$false -ErrorAction SilentlyContinue | Out-Null
Import-Module $PSScriptRoot\..\..\Common\ClusterHelpers.psm1 -DisableNameChecking -Verbose:$false -ErrorAction SilentlyContinue | Out-Null

Import-LocalizedData LocalizedStrings -FileName Roles.Strings.psd1 -ErrorAction SilentlyContinue
Import-LocalizedData LocalizedNetworkData -FileName Network.Strings.psd1 -ErrorAction SilentlyContinue

function Test-PSSession {
    Param(
        [Parameter(Mandatory=$true)]
        $RemoteSession,

        [Parameter(Mandatory=$true)]
        $SessionCredential,

        [Parameter(Mandatory=$true)]
        $SessionComputer
    )

    if (($RemoteSession -eq $null) -or ($RemoteSession.State -ne "Opened"))
    {
        Trace-Execution "Session not ready, state: $($RemoteSession.State)"
        Trace-Execution "Removing the session"
        $RemoteSession | Remove-PSSession

        Trace-Execution "Regenerating the session"
        $RemoteSession = New-PSSession -ComputerName $SessionComputer -Credential $SessionCredential

        Initialize-ECESession $RemoteSession
        Trace-Execution "State after regenerate = $($RemoteSession.State)"
    } else {
        Trace-Execution "Session Opened"
    }

    return $RemoteSession
}

# Make sure the MAC addresses and IPv4Address are loaded into Parameters object from the manifest.
function Set-MacAndIPAddressSingleNode {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory=$true)]
        [PSObject]
        $Node,

        [ValidateSet('PXE','Management')]
        [string]
        $IPv4AddressSource = 'PXE'
    )

    if (-not $node.MacAddress) {
        Trace-Execution "Failed to find MAC address for node '$($node.Name)' in the manifest. Skip this"
    }
    else
    {
        $macAddress = $node.MacAddress
        Trace-Execution "Normalizing MAC address '$macAddress'."
        # Normalize MAC address to .NET canonical form, e.g., E4-1D-2D-1D-25-30.
        $node.MacAddress = $node.MacAddress.ToUpper().Replace(':', '-')
    }

    $allHostNodes = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters

    $ipv4Address = $allHostNodes[$node.Name]
    Trace-Execution "Setting IPv4 address $ipv4Address for node $($node.Name) ."

    if(-not $node.IPv4Address) {
        $node | Add-Member -MemberType NoteProperty -Name "IPv4Address" -value $Ipv4Address
    } else {
        $node.IPv4Address = $ipv4Address
    }
}

function Set-MacAndIPAddress {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory = $true)]
        [System.Xml.XmlElement]
        $PhysicalMachinesRole,

        [ValidateSet('PXE','Management')]
        [string]
        $IPv4AddressSource = 'PXE',

        [Parameter(Mandatory=$false)]
        [System.Xml.XmlElement]
        $Node = $null
    )

    Trace-ECEScript "Setting IP addresses." {

        if ($Node)
        {
            Set-MacAndIPAddressSingleNode -Parameters $Parameters -Node $node -IPv4AddressSource $IPv4AddressSource
        }
        else
        {
            foreach ($node in $PhysicalMachinesRole.Nodes.Node)
            {
                Set-MacAndIPAddressSingleNode -Parameters $Parameters -Node $node -IPv4AddressSource $IPv4AddressSource
            }
        }
    }
}

function Get-BareMetalCredential
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $cloudRole = $Parameters.Roles['Cloud'].PublicConfiguration

    # Account info
    $securityInfo = $cloudRole.PublicInfo.SecurityInfo
    $bareMetalUser = $securityInfo.HardwareUsers.User | Where-Object -Property Role -EQ 'BareMetalAdmin'
    $bareMetalCredential = $Parameters.GetCredential($bareMetalUser.Credential)

    return $bareMetalCredential
}

# Gets the current active Domain Controller computer name.
function Get-AvailableADComputerName
{
 [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory = $true)]
        [String[]]
        $AllADComputerName,

        [Parameter(Mandatory = $false)]
        [PSCredential]
        $RemoteServiceCredentials = $null
    )
    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    Trace-ECEScript "Getting the current active Domain Controller computer name." {

        # Proactively look for AD running on local machine (in case of multi-node, this will return the DVM).
        $service = Get-Service -Name "NTDS" -ErrorAction SilentlyContinue
        if($service -and $service.Status -eq "Running")
        {
            $activeADComputer = $env:COMPUTERNAME
        }
        else
        {
            # In case of one Node or post deployment, this will return DC01.
            foreach($adComputer in $AllADComputerName)
            {
                if ($RemoteServiceCredentials)
                {
                    try
                    {
                        $psSession = New-PsSession -Credential $RemoteServiceCredentials -ComputerName $adComputer -ErrorAction SilentlyContinue
                        if($psSession)
                        {
                            $service = Invoke-Command -Session $psSession -ScriptBlock { Get-Service -Name "NTDS" -ErrorAction SilentlyContinue }
                        }
                    }
                    finally
                    {
                        if ($psSession)
                        {
                            Remove-PsSession $psSession
                        }
                    }
                }
                else
                {
                    $service = Invoke-Command -ComputerName $adComputer -ScriptBlock { Get-Service -Name "NTDS" -ErrorAction SilentlyContinue } -ErrorAction SilentlyContinue
                }

                if ($service -and $service.Status -eq "Running")
                {
                    $activeADComputer = $adComputer
                    break
                }
            }
        }
    }

    if($activeADComputer)
    {
        Trace-Execution "Found AD running on $activeADComputer"
        return $activeADComputer
    }
    else
    {
        Trace-Error "No Available AD computer found."
    }
}

# Virtual Network Common
function Test-NetworkMap {
    param (
        [Parameter(Mandatory=$true)]
        $NetworkMap,

        [Parameter(Mandatory=$false)]
        [UInt32] $RetryCount = 0,

        [Parameter(Mandatory=$false)]
        [UInt32] $RetryIntervalInSeconds = 60,

        [Parameter(Mandatory=$false)]
        [string[]] $NodeNames
    )

    Trace-ECEScript $LocalizedNetworkData.CheckNICConnectivity {

        $nodesToCheck = $NetworkMap.Keys
        if ($NodeNames) {
            $nodesToCheck = $nodesToCheck | Where-Object {$_ -in $NodeNames}
        }

        $retry = 0
        do
        {
            try
            {
                # Test nic connectivity for each machine
                foreach ($nodeName in ($nodesToCheck | Sort-Object))
                {
                    $node = $NetworkMap.$nodeName
                    $hasPingableConnections = $false

                    foreach ($nicId in ($node.Keys | Sort-Object))
                    {
                        $nic = $NetworkMap.$nodeName.$nicId
                        try
                        {
                            # This cast will fail if the IP address isn't well-formed
                            $ipAddress = [ipaddress]$nic.IPv4Address.Split('/')[0]
                            $canPing = Test-IPConnection $ipAddress.IPAddressToString
                        }
                        catch
                        {
                            $canPing = $false
                        }

                        if ($canPing) {
                            $hasPingableConnections = $true
                        }

                        $nic | Add-Member -MemberType NoteProperty -Name CanPing -Value $canPing

                        Trace-Execution "$(if ($canPing) {'+'} else {'-'}) $nodeName | $($nic.Name)"
                    }

                    if (-not $hasPingableConnections) {
                        throw ($LocalizedNetworkData.NoPingableConnections -f $nodeName)
                    }
                }
                break
            }
            catch
            {
                if($retry -eq $RetryCount) {
                    throw
                }
                Trace-Execution "Test-NetworkMap failed. Will retry in $RetryIntervalInSeconds seconds. Retry attempted: $retry."
                Start-Sleep -Seconds $RetryIntervalInSeconds
            }
            $retry++
        } while ($retry -le $RetryCount)
    }
}

function Get-IsVirtualNetworkAlreadyConfigured {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        $NetworkMap,

        [Parameter(Mandatory=$true)]
        $IsOneNode
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    # Check that all non-Deployment vNICs can be pinged.
    $notPingableAdapters = $NetworkMap.Values.Values | ? CanPing -ne $true

    if (-not $notPingableAdapters)
    {
        Trace-Execution $LocalizedNetworkData.NetworkingAlreadyConfigured
        return $true
    }

    return $false
}

# BUGBUG: This function may not needed any more in ASZ. Leave it here to not break existing code. Need refactoring.
function Get-NetworkMap {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        $PhysicalMachinesRole
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    $nodeNames = $PhysicalMachinesRole.Nodes.Node | % Name

    Trace-ECESCript "Get Network Map for nodes $nodeNames" {

        # If multiple nodes are being added at the same time, only test those that are being deployed by the current action plan instance
        $executionRoleName = $Parameters.Context.ExecutionContext.Roles.Role.RoleName
        $hostsList = $Parameters.Context.ExecutionContext.Roles.Role.Nodes.Node.Name

        if ($executionRoleName -ieq "Cluster")
        {
            $hostsList = $null
            $hostsList = [array]($Parameters.Context.ExecutionContext.Roles.Role.Nodes.Node.PhysicalNodes.PhysicalNode.Name)
        }

        $networkmap = @{}
        $allHostNodes = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters

        foreach ($node in $PhysicalMachinesRole.Nodes.Node)
        {
            if (-not($node.OperationStatus -eq "RequiresRemediation") -and (-not($node.OperationStatus -eq "Adding") -or ($hostsList -contains $node.Name)))
            {
                # there would be only 1 IP on each host that may need checking.
                $nodeNics = @{}

                $nicIPv4 = $allHostNodes[$node.Name]
                $nicName = $node.Name

                if (-not (Test-NetworkIPv4Address -IPv4Address $nicIPv4))
                {
                    Trace-Execution "[Get-NetworkMap]: IPv4 Address for node $($node.Name) $nicIPv4 is not with expected format, skip."
                    continue
                }

                $nicData = New-Object PSObject -Property @{
                    Name = $nicName
                    IPv4Address = $nicIPv4
                }

                $nodeNics.$nicName = $nicData
                $networkMap.($node.Name) = $nodeNics
            }
        }
    }

    return $networkMap
}

function Wait-VirtualNetwork {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        $PhysicalMachinesRole,

        [Boolean]
        $IsIdempotentRun = $true,

        [Parameter(Mandatory=$false)]
        [string] $UpdateNodeName
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    Trace-ECEScript "Waiting for Virtual Network to be configured on the host." {
        $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
        $securityInfo = $cloudRole.PublicInfo.SecurityInfo
        $localAdminUser = $securityInfo.LocalUsers.User | ? Role -EQ $Parameters.Configuration.Role.PrivateInfo.Accounts.BuiltInAdminAccountID
        $credential = $Parameters.GetCredential($localAdminUser.Credential)

        # in the case of Bare Metal the hosts, it is possible that the DSC hasn't completed the configuration for the hosts at this point,
        # so add some retry logic to test the network connectivity
        $networkMap = Get-NetworkMap -Parameters $Parameters -PhysicalMachinesRole $PhysicalMachinesRole
        if ($UpdateNodeName) {
            Test-NetworkMap -NetworkMap $networkMap -RetryCount 10 -NodeNames @($UpdateNodeName)
        }
        else {
            Test-NetworkMap -NetworkMap $networkMap -RetryCount 10
        }

        $nodes = $PhysicalMachinesRole.Nodes.Node
        $nodeNames = $nodes | ForEach-Object Name
        $jobs = @()

        $isOneNode = $false
        if ($UpdateNodeName) {
            # For update, only one host is service at a time and this should not get confused with One Node MAS environment
            $nodes = $nodes | Where-Object Name -eq $UpdateNodeName
        }
        elseif ($nodeNames.Count -eq 1 ) {
            $isOneNode = $true
            # MASD One Node will always be run locally
            $nodeNames = 'LocalHost'
        }

        if ($IsIdempotentRun) {
            if (Get-IsVirtualNetworkAlreadyConfigured -NetworkMap $networkMap -IsOneNode $isOneNode) {
                return
            }
        }

        $allHostNodes = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        if ($env:OSImageType -ne "ISO") {
            Trace-ECEScript "Start PowerShell jobs to retrieve and set the DSC state on all nodes $nodeNames." {
                foreach ($node in $nodes) {
                    # Collect information about the state of the recently deployed physical host.
                    $managementIpAddress = $allHostNodes[$node.Name]
                    $nodeName = $node.Name
                    Trace-Execution "Sending DSC query to $managementIpAddress for $nodeName"
                    $jobs += Start-Job -ScriptBlock {
                        $retVal = $false
                        $logText = "DSC report for node $(($using:Node).Name)`r`n"

                        # Wait as much as ten minutes for the exiting DSC configuration to complete. This is just a best effort.
                        for ($i = 0; $i -lt 40; $i++) {
                            $cimSession = $null
                            $result = $null
                            try {
                                # This call may fail if it can't connect to the remote host when remote host is configuring vmswitch and host vnic.
                                $cimSession = New-CimSession -ComputerName $Using:nodeName -Credential $using:credential -ErrorAction SilentlyContinue
                                if ($null -eq $cimSession) {
                                    $cimSession = New-CimSession -ComputerName $using:managementIpAddress -Credential $using:credential -ErrorAction Stop
                                }
                                # This call will throw exception if there is currently a DSC config running on the host.
                                # we use it as a way as an indication.
                                $logText += "Calling Get-DscConfigurationStatus at attempt #$i. `r`n"
                                $result = Get-DscConfigurationStatus -CimSession $cimSession -ErrorAction Stop
                                break
                            }
                            catch {
                                Start-Sleep -Seconds 15
                                $logText += "Get-DscConfigurationStatus failed with exception ($($_.Exception.Message)) at attempt #$i `r`n"
                            }
                            finally {
                                if ($cimSession) {
                                    Remove-CimSession $cimSession
                                }
                            }
                        }

                        $logText += "Trying to make sure host DSC configuration is completed. `r`n"
                        for ($i = 0; $i -lt 5; $i++) {
                            $cimSession = $null
                            try {
                                $cimSession = New-CimSession -ComputerName $Using:nodeName -Credential $using:credential -ErrorAction SilentlyContinue
                                if ($null -eq $cimSession) {
                                    $cimSession = New-CimSession -ComputerName $using:managementIpAddress -Credential $using:credential -ErrorAction Stop
                                }
                                $logText += "Calling Start-DscConfiguration at attempt #$i `r`n"
                                Start-DscConfiguration -UseExisting -Wait -CimSession $cimSession -Verbose -Force -ErrorAction Stop
                                $logText += "Calling Get-DscConfigurationStatus at attempt #$i. `r`n"
                                $result = Get-DscConfigurationStatus -CimSession $cimSession -ErrorAction Stop
                                $logText += "Calling Get-DscConfiguration at attempt #$i. `r`n"
                                $logText += (Get-DscConfiguration -CimSession $cimSession -Verbose -ErrorAction Stop | out-string)
                            }
                            catch {
                                # While DSC configuration on the host is running, it may cause the network connectivity to be disrupted.
                                # If that disruption last too long, say more than 3 or 4 minutes, the above calls may fail with exception.
                                # So catch the exception here but do nothing.
                                $logText += "Attempt #$i : failed with exception ($($_.Exception.Message)). `r`n"
                            }
                            finally {
                                if ($result.status -eq 'Success') {
                                    $retVal = $true
                                }

                                if ($cimSession) {
                                    Remove-CimSession $cimSession
                                }
                            }
                            if ($retVal) {
                                break
                            }
                        }

                        $retObj = @{RetVal = $retVal; LogText = $logText; HostIp = $using:managementIpAddress}
                        $retObj
                    }
                }
            }

            # Wait for all the nodes to either converge or fail to converge. If they failed to
            # converge, or if we failed to send the WSManAction to them, then use the more stateful
            # networking methods to figure out why, later.
            Trace-ECEScript "Waiting for DSC query to complete" {
                $results = Receive-Job -Wait -Job $jobs
                $results | ForEach-Object {
                    Trace-Execution $_.LogText
                    if ($_.RetVal -ne $true) {
                        Trace-Error "DSC failed to converge on a physical host $($_.HostIp)."
                    }
                }
            }

            $jobs | Remove-Job -ErrorAction SilentlyContinue
        }
        else {
            Trace-Execution "Skipping wait for DSC config as this is an ISO-based deployment."
        }
    }
}

function Get-DomainIPMapping
{
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $domainIPMapping = @{}
    $deploymentMachineRoleNode = $Parameters.Roles["DeploymentMachine"].PublicConfiguration.Nodes.Node

    if($deploymentMachineRoleNode -ne $null)
    {
        $domainIPMapping.Add($deploymentMachineRoleNode.Name, $deploymentMachineRoleNode.IPv4Address)
    }

    return $domainIPMapping
}

# Get the node names from the ExecutionContext in the $Parameters variable
# if available; otherwise, return $null
function Get-ExecutionContextNodeName
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory = $false)]
        [switch]
        $EnsureSingle
    )

    $nodeName = $null
    $executionRoleName = $Parameters.Context.ExecutionContext.Roles.Role.RoleName
    $nodeName = $Parameters.Context.ExecutionContext.Roles.Role.Nodes.Node.Name

    if ($null -ne $executionRoleName -and $null -eq $nodeName)
    {
        # If node names are not provided, get all nodes associated to the $executionRoleName
        $nodeName = ($Parameters.Roles[$executionRoleName].PublicConfiguration.Nodes.Node.Name) | Select-Object -Unique
    }

    Trace-Execution "Received ExecutionContext with role name $executionRoleName and node(s): $($nodeName -join ', ')"

    if ($EnsureSingle -and (!$nodeName -or ($nodeName.Count -ne 1)))
    {
        throw "Expected single node in ExecutionContext but found node(s): $($nodeName -join ', ')"
    }

    return $nodeName
}

# Get the cluster name from the ExecutionContext in the $Parameters variable
# if available; otherwise, return $null
function Get-ExecutionContextClusterName
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $executionRoleName = $Parameters.Context.ExecutionContext.Roles.Role.RoleName
    $clusterName = $Parameters.Context.ExecutionContext.Roles.Role.Nodes.Node.ClusterName
    Trace-Execution "Received ExecutionContext with role name $executionRoleName and clusterName : $clusterName"

    return $clusterName
}

# Gets the names of the roles specified in the execution context.
function Get-ExecutionContextRoleName
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    # ExecutionContext can specify RolePath and/or RoleName attributes. Since we want just the names
    # we truncate the role paths if they are the only attribute provided, and return a list of the unique role names.
    $executionRoleName = @( $Parameters.Context.ExecutionContext.Roles.Role.RoleName )
    $executionRolePath = @( $Parameters.Context.ExecutionContext.Roles.Role.RolePath )

    $executionRoleName += $executionRolePath | Split-Path -Leaf
    return ($executionRoleName | Select-Object -Unique)
}

# Determines whether the environment is one-node from the interface parameters.
function IsOneNode
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    return @($Parameters.Roles["Storage"].PublicConfiguration.Nodes.Node).Count -eq 1
}

# Determines whether the environment is virtual from the interface parameters.
function IsVirtualAzureStack
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $oemModel = $Parameters.Roles["OEM"].PublicConfiguration.PublicInfo.UpdatePackageManifest.UpdateInfo.Model
    $supportedModelList = $Parameters.Roles["OEM"].PublicConfiguration.PublicInfo.UpdatePackageManifest.UpdateInfo.SupportedModels.SupportedModel
    if ($null -eq $supportedModelList)
    {
        # The model string reported by BIOS and recorded by ExtractOEMContent.ps1 will still have spaces and special characters
        return (@("Virtual Machine", "Hyper-V") -contains $oemModel)
    }
    else
    {
        # The supported model list will have had spaces and special characters removed
        return ($supportedModelList -contains "VirtualMachine")
    }
}

# This function checks whether the deployment is running on Virtual Machine by system prams
function IsOnVirtualMachine
{
    try
    {
        # is on VM
        $computerSystem = Get-WmiObject win32_computersystem
        $isOnVM = (('Microsoft Corporation' -eq $computerSystem.Manufacturer) -and ('Virtual Machine' -eq  $computerSystem.Model))
    }
    catch
    {
        Trace-Error "Error while checking system info for Virtual Machine deployment"
        return $false
    }

    return $isOnVM
}

# Checks the RunInformation for UpdateVersion. Returns the value if found else returns null
function Get-InProgressUpdateVersion
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $version = $null
    Trace-Execution "Getting in progress Update Version."
    # In case of update, run time information will be populated
    if($Parameters.RunInformation -ne $null)
    {
        $runtimeParameters = $Parameters.RunInformation['RuntimeParameter']

        if( $runtimeParameters -ne $null -and $runtimeParameters.ContainsKey('UpdateVersion') )
        {
            $version = $runtimeParameters["UpdateVersion"]
            Trace-Execution "Version of the update being applied : $version"
            return $version
        }
    }

    # If it is a one node or bootstrap VM return null as an update will not run on it.
    $buildLocally = $Parameters.Context.ExecutionContext.BuildVhdLocally -and [bool]::Parse($Parameters.Context.ExecutionContext.BuildVhdLocally)
    $RoleName = $Parameters.Configuration.Role.Id
    $isOneNode = @($Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node).Count -eq 1
    if(($isOneNode -eq $true) -or ($buildLocally -and ($RoleName -eq "Domain")))
    {
        return $version
    }

    # If the version is set to null, check if share has update version info file.
    # This file only exists while a host is being updated.
    if($version -eq $null)
    {
        $bareMetalRole = $Parameters.Roles["BareMetal"].PublicConfiguration
        $storageClusterName = Get-ManagementClusterName $Parameters
        if($bareMetalRole.PublicInfo.UpdateInformation -ne $null)
        {
            $updateInfoFolderPath = Get-SharePath $Parameters $bareMetalRole.PublicInfo.UpdateInformation.UpdateVersionFile.FolderName $storageClusterName
            $updateInfoFileName = $bareMetalRole.PublicInfo.UpdateInformation.UpdateVersionFile.FileName
            $filePath = Join-Path -Path $updateInfoFolderPath -ChildPath $updateInfoFileName
            Trace-Execution "Check if version file $filePath exists"
            if(Test-Path -Path $filePath)
            {
                Trace-Execution "The version file is present. Extracting version number and override status from it"
                $versionFileContent = [xml] ( Get-Content -Path $filePath )
                if($versionFileContent)
                {
                    $versionValue = $versionFileContent.InProgressUpdateVersion.Version
                    $useThisVersion = $versionFileContent.InProgressUpdateVersion.UseThisVersion
                    if($useThisVersion -eq "True")
                    {
                        $version = $versionValue
                    }
                    else
                    {
                        Trace-Error "The version file exists but is not being used as UseThisVersion flag is set to False. This flag should be set to True if FRU is being used to recover from an update failure"
                    }
                }
                else
                {
                    Trace-Error "Version file found at $filePath but has invalid content"
                }
            }
        }
    }

    return $version
}

# Gets the file share directory containing expanded contents of a currently in-progress update package.
function Get-InProgressUpdatePackagePath
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )
    $runtimeParameters = $Parameters.RunInformation['RuntimeParameter']
    $packagePath = $runtimeParameters["UpdatePackagePath"]
    if (-not $packagePath)
    {
        Trace-Execution "The UpdatePackagePath runtime parameter is not present."
        return $null
    }

    Trace-Execution "Upgrade package @: [$packagePath]"

    # The package path is expected to be a full path to an update package file (e.g. a self-
    # extracting .exe, or a metadata.xml file). The path where the contents are extracted is
    # the directory containing this file.
    return (Split-Path $packagePath)
}

# Gets the location of the folder containing nugets in the currently in-progress update package.
function Get-InProgressUpdateNugetStore
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $updatePackagePath = Get-InProgressUpdatePackagePath -Parameters $Parameters
    if ($updatePackagePath)
    {
        $urpRole = $Parameters.Roles["URP"].PublicConfiguration
        $nugetSourceFolderName = ($urpRole.PublicInfo.UpdatePackagePaths.ContentMappings.ContentMapping | Where-Object { $_.Name -eq "Nugets" }).SourceFolder

        $nugetStorePath = Join-Path $updatePackagePath $nugetSourceFolderName
        if (Test-Path $nugetStorePath)
        {
            Trace-Execution "Found update nuget store at $nugetStorePath."
            return $nugetStorePath
        }

        # Fallback: check for legacy nuget store path.
        $nugetSourceFolderName = ($urpRole.PublicInfo.UpdatePackagePaths.ContentMappings.ContentMapping | Where-Object { $_.Name -eq "NugetsLegacy" }).SourceFolder
        $nugetStorePath = Join-Path $updatePackagePath $nugetSourceFolderName
        if (Test-Path $nugetStorePath)
        {
            Trace-Execution "Found legacy update nuget store at $nugetStorePath."
            return $nugetStorePath
        }

        Trace-Execution "No nuget store was found at update package path: $updatePackagePath."
    }
    else
    {
        Trace-Execution "No update is currently in progress."
    }

    return $null
}

<#
.SYNOPSIS
Expands the deployment artifacts to the destination location.
 
.DESCRIPTION
Expands all deployment artifacts into the destination root path.
 
.EXAMPLE
Expand-DeploymentArtifacts -DeploymentContentNode $Parameters.Configuration.Role.PrivateInfo.DeploymentContent -DestinationRootPath "C:"
 
.PARAMETER DeploymentContentNode
The xml node containing the deployment content to deliver to the destination.
 
.PARAMETER DestinationRootPath
The root path under which to deliver the nuget content.
#>

function Expand-DeploymentArtifacts
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [System.Xml.XmlElement]
        $DeploymentContentNode,

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

        [Parameter(Mandatory=$false)]
        [string]
        $NugetStorePath = "$env:SystemDrive\CloudDeployment\NuGetStore"
    )

    $nugetDeploymentContentItems = $DeploymentContentNode.NugetArtifact

    $installRolePackages = $false
    $rolePackageDestination = Join-Path $DestinationRootPath 'NugetStore'
    foreach( $deployContent in $nugetDeploymentContentItems )
    {
        Write-Verbose -Verbose "Copying content from nuget $($deployContent.Name) into $DestinationRootPath"
        $destination = Join-Path $DestinationRootPath $deployContent.DestinationPath

        $sourceIsFile = [bool]$deployContent.SourceIsFile
        $isNugetInstall = [bool]$deployContent.NugetInstall

        if($isNugetInstall)
        {
            $installRolePackages = $true
        }

        Write-Verbose -Verbose "$($deployContent.SourcePath) will be copied to $destination"
        Write-Verbose -Verbose "IsNugetInstall : $isNugetInstall"
        Expand-NugetContent -NugetName $deployContent.Name -SourcePath $deployContent.SourcePath -DestinationPath $destination -SourceIsFile:$sourceIsFile -Verbose:$VerbosePreference -NugetStorePath $NugetStorePath -IsNugetInstall:$isNugetInstall
        Write-Verbose -Verbose "Nuget $($deployContent.Name) with source [$($deployContent.SourcePath)] copied to $destination"
    }

    if($installRolePackages)
    {
        Write-Verbose -Verbose "Install Role Nuget packages to NugetStore"
        Install-RoleNugetPackages -NugetStorePath $NugetStorePath -Destination $rolePackageDestination
    }
}

function Expand-UpdateContent
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory=$false)]
        [string[]]
        $ExecutionRoleName,

        [Parameter(Mandatory=$false)]
        [switch]
        $DSCOnly,

        [Parameter(Mandatory=$false)]
        [switch]
        $EngineUpdateOnly,

        [Parameter(Mandatory=$false)]
        [string[]]
        $NodeName
    )

    $currentContext = $Parameters.Context.ExecutionContext
    if(-not $ExecutionRoleName)
    {
        $ExecutionRoleName = $currentContext.Roles.Role.RoleName
    }

    $vmRole = $Parameters.Roles["VirtualMachines"].PublicConfiguration

    $localExecutionHost = $env:COMPUTERNAME
    $clusterName = Get-ManagementClusterName $Parameters
    $allManagementHosts = Get-ManagementClusterNodes $Parameters

    $uncLibraryShareNugetStorePath = Get-SharePath $Parameters $vmRole.PublicInfo.LibraryShareNugetStoreFolder.Path $clusterName

    # During AsZ deployment expand nugets on all the nodes part of cluster
    # Cluster path at this time doesn't exist so use the absolute path
    if (!(Test-Path -Path $uncLibraryShareNugetStorePath))
    {
        Trace-Execution "AsZ deployment scenario so use absolute path on SeedNode"
        $uncLibraryShareNugetStorePath = "$env:SystemDrive\CloudDeployment\NuGetStore"
    }

    $localLibraryShareNugetStorePath = $null
    # Bug 15111454: Waiting for fix it should not block deployment
    # if(Test-LocalHostHasClusterStoragePath -Parameters $Parameters)
    # {
    # Trace-Execution "Getting local CSV path for $uncLibraryShareNugetStorePath"
    # $localLibraryShareNugetStorePath = Get-LocalCsvPathFromSharePath -Parameters $Parameters -UNCSharePath $uncLibraryShareNugetStorePath
    # }

    Trace-Execution "uncLibraryShareNugetStorePath: $uncLibraryShareNugetStorePath"
    Trace-Execution "localLibraryShareNugetStorePath: $localLibraryShareNugetStorePath"

    $systemDrive = $env:SystemDrive -Replace (':','$')
    $healthyNodes = $Parameters.Roles["VirtualMachines"].PublicConfiguration.Nodes.Node | where { $_.ProvisioningStatus -eq "Complete" } | % Name
    $healthyNodes += $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node | where { $_.ProvisioningStatus -eq "Complete" } | % Name

    foreach ($roleName in $ExecutionRoleName)
    {
        Trace-Execution "Expand-UpdateContent adding update contents for role: $roleName"
        $roleConfiguration = $Parameters.Roles[$roleName].PublicConfiguration
        if ($NodeName)
        {
            $nodes = $NodeName
        }
        else
        {
            $nodes = $roleConfiguration.Nodes.Node.Name |where { $healthyNodes.Contains($_)}
        }

        Trace-Execution "Expand-UpdateContent for Nodes : $($nodes)"

        # Skipping nodes which are provided in runtime parameters
        $nodes = Skip-NodesProvidedInRuntimeParameter -Parameters $Parameters -Nodes $nodes

        Trace-Execution "Expand-UpdateContent for Nodes (after filtering) : $($nodes)"

        # Get update content for the role
        $nugetUpdateContentItems = $roleConfiguration.PublicInfo.DeploymentContent.NugetArtifact | where {$_.Update -eq "True" -or $_.EngineUpdate -eq "True"}

        $allNodesNameIpMappingInfo = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Copy the update content
        if ($nugetUpdateContentItems)
        {
            foreach( $updateContent in $nugetUpdateContentItems )
            {
                if($DSCOnly -and ($updateContent.DSCContent -ne "True"))
                {
                    Trace-Execution "$($updateContent.Name) is not marked as nuget with DSC content. Skipping update on the target VM(s) "
                    continue
                }
                elseif ($EngineUpdateOnly -and ($updateContent.EngineUpdate -ne "True"))
                {
                    Trace-Execution "$($updateContent.Name) is not marked as nuget with engine content. Skipping update on the target VM(s)."
                    continue
                }

                foreach ($node in $nodes)
                {
                    $libraryShareNugetStorePath = $null
                    if (($node -in $allManagementHosts) -and ($null -ne $localLibraryShareNugetStorePath))
                    {
                        Trace-Execution "For node $node - member the management cluster - will use local nuget store path $localLibraryShareNugetStorePath"
                        $libraryShareNugetStorePath = $localLibraryShareNugetStorePath
                    }
                    else
                    {
                        Trace-Execution "For node $node will use UNC nuget store path $uncLibraryShareNugetStorePath"
                        $libraryShareNugetStorePath = $uncLibraryShareNugetStorePath
                    }

                    Trace-Execution "Start process to expand nuget content:"
                    Trace-Execution "Local execution host : $localExecutionHost"
                    Trace-Execution "Nuget store Path : $libraryShareNugetStorePath"
                    Trace-Execution "Processing node : $node"

                    $nodeIp = $allNodesNameIpMappingInfo[$node]

                    $DestinationRootPath = "\\$nodeIp\$systemDrive\"
                    if ($updateContent.UpdatePath)
                    {
                        $destination = Join-Path $DestinationRootPath $updateContent.UpdatePath
                    }
                    else
                    {
                        $destination = Join-Path $DestinationRootPath $updateContent.DestinationPath
                    }

                    $isNugetInstall = $null
                    [bool]::TryParse($updateContent.NugetInstall, [ref]$isNugetInstall)

                    Expand-NugetContent -NugetName $updateContent.Name -SourcePath $updateContent.SourcePath -DestinationPath $destination -IsUnc -NugetStorePath $libraryShareNugetStorePath -IsNugetInstall:$isNugetInstall
                    Write-Verbose -Verbose "$($updateContent.SourcePath) copied to $destination"
                }
            }
        }
    }
}

#execute to a script block over a VMGroup using PSDirect instead of WinRM
function Invoke-PSDirectOnVM
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory = $true)]
        [String[]]$VMNames,

        [Parameter(Mandatory = $true)]
        [Object]$VMCredential,

        [Parameter(Mandatory = $true)]
        [ScriptBlock]$ScriptBlock,

        [Object[]]$ArgumentList = $null
    )
    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    #retrieve the environment info
    $allPhysicalMachines = Get-ActiveClusterNodes $Parameters

    # Domain Info
    $domainAdminCredential = Get-DomainCredential -Parameters $Parameters

    # for each physical host, iterate over all the infra VMs that are part of it
    $hostTrace = @()
    foreach ($phyHost in $allPhysicalMachines) {
        Trace-Execution "For Host $($phyHost)"

        # test if the target host is reachable
        $output = $false
        $output = Test-WSMan -ComputerName $phyHost -ErrorAction:Ignore
        if (-not $output)
        {
            Write-Host "Host $($phyHost) not responding..."
            continue
        }
        $localHostTrace = Invoke-Command -ComputerName $phyHost -Credential $domainAdminCredential -ScriptBlock {
            $vmTrace = @()
            $thrownExceptions = @()
            # get the infra VMs in this physical node
            $retries = 5
            for($retry = 0; $retry -lt $retries; ++$retry)
            {
                try
                {
                    # Unfiltered calls to Get-VM may fail if a VM is being deleted from that host
                    $localVMs = (Get-VM | ? Name -In $using:VMNames).Name
                    break
                }
                catch
                {
                    if ($retry -eq $retries - 1)
                    {
                        throw
                    }
                }
            }
            if($localVMs) {
                Trace-Execution "Executing on local VMs $($localVMs -join ',')"
                try {
                    # change PS language mode to FULL to allow script block invocation
                    if (!$using:ArgumentList) {
                        $vmTrace += Invoke-Command -VMName $localVMs -Credential $using:VMCredential -ScriptBlock ([ScriptBlock]::Create($("Import-Module OpenUpSession; Set-FullLanguage; `r`n" + $using:ScriptBlock)))
                    }
                    # check if the scriptblock declares Param because special handling is needed
                    elseif ($using:ScriptBlock -match "param[ ]*\(|param[ ]*\r\n")
                    {
                        $sb = {param($ScriptBlock, [Object[]]$ArgumentList) Import-Module OpenUpSession; Set-FullLanguage; [scriptBlock]::Create($ScriptBlock).invoke($ArgumentList)}
                        $vmTrace += Invoke-Command -VMName $localVMs -Credential $using:VMCredential -ScriptBlock $sb -ArgumentList $using:ScriptBlock, $using:ArgumentList
                    }
                    else
                    {
                        $vmTrace += Invoke-Command -VMName $localVMs -Credential $using:VMCredential -ArgumentList $using:ArgumentList -ScriptBlock ([ScriptBlock]::Create($("Import-Module OpenUpSession; Set-FullLanguage; `r`n" + $using:ScriptBlock)))
                    }
                } catch {
                    Write-Host "Local exception: $($_)"
                    $thrownExceptions += $_
                }
            }
            if ($vmTrace)
            {
                Write-Host "VM(s) returned: $vmTrace"
            }
            if ($thrownExceptions.Count -gt 0) {
               throw $thrownExceptions
            }
            return $vmTrace
        }
        if ($localHostTrace)
        {
            Trace-Execution "Local Host Output: $($localHostTrace)"
        }
        $hostTrace += $localHostTrace
    }
    return $hostTrace
}

function Invoke-ScriptBlockWithRetries
{
    [CmdletBinding(DefaultParameterSetName="All")]
    param(
        [ScriptBlock]
        [parameter(Mandatory = $true)]
        $ScriptBlock,

        [Int32]
        [parameter(Mandatory = $false)]
        $RetryTimes = 10,

        [Int32]
        [parameter(Mandatory = $false)]
        $RetrySleepTimeInSeconds = 10,

        [Switch]
        [parameter(Mandatory = $false)]
        $InDisconnectedSession=$false,

        [string]
        [parameter(Mandatory = $false, ParameterSetName="ByComputerName")]
        $ComputerName = $null,

        [PSCredential]
        [parameter(Mandatory = $false)]
        $Credential = $null,

        [parameter(Mandatory = $false, ParameterSetName="BySession")]
        $Session = $null,

        [parameter(Mandatory = $false)]
        $ArgumentList = $null
    )
    $ErrorActionPreference = "Stop"

    for($retry = 0; $retry -lt $RetryTimes; ++$retry)
    {
        try
        {
            Write-Verbose "Invoke-ScriptBlockWithRetries: retry #$retry of $RetryTimes, retry sleep time is $RetrySleepTimeInSeconds seconds." -Verbose

            $invokeParams = @{
            }

            $noNewScope = $true
            if ($ComputerName)
            {
                $invokeParams.ComputerName = $ComputerName
                $noNewScope = $false
            }
            elseif ($Session)
            {
                $invokeParams.Session = $Session
                $noNewScope = $false
            }

            if ($Credential)
            {
                $invokeParams.Credential = $Credential
                $noNewScope = $false
            }

            if ($noNewScope)
            {
                $invokeParams.NoNewScope = $true
            }

            if ($InDisconnectedSession)
            {
                $invokeParams.InDisconnectedSession = $true
            }

            if ($ArgumentList)
            {
                $invokeParams.ArgumentList = $ArgumentList
            }

            $invokeParams.ScriptBlock = $ScriptBlock

            return Invoke-Command @invokeParams
        }
        catch
        {
            Write-Verbose "Invoke-ScriptBlockWithRetries failed with exception: $_" -Verbose

            if ($retry -lt ($RetryTimes - 1))
            {
                Start-Sleep -Seconds $RetrySleepTimeInSeconds
            }
            else
            {
                throw
            }
        }
    }
}

function Invoke-ScriptBlockInParallel
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string[]]
        $ComputerNames,

        [Parameter(Mandatory=$false)]
        [PSCredential]
        $Credential,

        [ScriptBlock]
        [parameter(Mandatory = $true)]
        [ValidateScript({$_ -NotLike '*$Using:*'})]
        $ScriptBlock,

        [Object[]]
        [parameter(Mandatory = $false)]
        $ArgumentList = $null,

        [Int32]
        [parameter(Mandatory = $false)]
        $RetryTimes = 2,

        [Int32]
        [parameter(Mandatory = $false)]
        $RetrySleepTimeInSeconds = 5,

        [Parameter(Mandatory = $false)]
        [string]
        $Authorization = 'Default'
    )

    $ErrorActionPreference = 'Stop'

    $computerNames = $ComputerNames
    $jobs = @()
    $sessions =@()
    $errorMessages = @()

    # Just retry for kicking off the ScriptBlock in Parallel
    for ($retry = 0; $retry -lt $RetryTimes; ++$retry)
    {
        $retryComputers = @()
        $session = $null
        $job = $null

        Trace-Execution "Invoke-ScriptBlockInParallel: retry #$retry of $RetryTimes, retry sleep time is $RetrySleepTimeInSeconds seconds, machines are $computerNames."

        foreach ($computerName in $computerNames)
        {
            try
            {
                if($Credential)
                {
                    $session = New-PSSession -ComputerName $computerName -Credential $Credential -Authentication $Authorization
                }
                else
                {
                    $session = New-PSSession -ComputerName $computerName
                }

                Initialize-ECESession -Session $session
                $job = Invoke-Command -ErrorAction Stop -Session $session -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList -AsJob
                $sessions += $session
                $jobs += $job
            }
            catch
            {
                $retryComputers += $computerName
                $errorMessage = "Machine $computerName failed with error: $($_.Exception.Message)"
                $errorMessages +=  $errorMessage

                if ($session -ne $null)
                {
                    $session | Remove-PSSession -ErrorAction Ignore
                }

                if ($job -ne $null)
                {
                    $job | Remove-Job -ErrorAction Ignore
                }
            }
        }

        if (($retryComputers.Count -eq 0) -or ($retry -ge ($RetryTimes -1)))
        {
            Trace-Execution "Invoke-ScriptBlockInParallel exits from retries for kicking off jobs in $retry retries"
            break
        }

        $computerNames = $retryComputers
        Start-Sleep -Second $RetrySleepTimeInSeconds
        $errorMessages = @()
    }

    # Waiting for all jobs to finish
    try
    {
        if ($jobs.Count -eq 0)
        {
            $errorMessage = "Invoke-ScriptBlockInParallel failed: Script could not be invoked after $RetryTimes retries"
            $errorMessages +=  $errorMessage
            throw "Invoke-ScriptBlockInParallel failed: $errorMessages"
        }

        Trace-Execution "Invoke-ScriptBlockInParallel: Waiting for jobs"

        $jobs | Wait-Job | Receive-Job

        Trace-Execution "Invoke-ScriptBlockInParallel: finished jobs"

        $failedJobs =  $jobs | ? { $_.JobStateInfo.State -ne "Completed" }

        foreach ($failedJob in $failedJobs)
        {
            $newErrorMessage = $null
            try
            {
                $newErrorMessage = $failedJob.ChildJobs[0].JobStateInfo.Reason.Message
            }
            catch
            {
            }

            $errorMessages += "Machine $($failedJob.Location): Failed with error: $newErrorMessage"
        }

        if ($errorMessages.Count -gt 0)
        {
            throw "Invoke-ScriptBlockInParallel failed: $errorMessages"
        }
    }
    finally
    {
        $sessions | Remove-PSSession -ErrorAction Ignore
        $jobs | Remove-Job -ErrorAction Ignore
    }
}

<#
.SYNOPSIS
    Create a folder on management file share for host update
 
.DESCRIPTION
    This function creates a folder on management file share for host update
 
.PARAMETER Parameters
    This object is based on the customer manifest. It contains the private information and public
    information of cloud role. This Parameters object is passed down by the deployment engine.
 
#>

function Get-HostUpdateShare
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    Trace-ECEScript "Getting the host update share." {
        $physicalMachinesRole = $Parameters.Roles["BareMetal"].PublicConfiguration

        $clusterName = Get-ManagementClusterName $Parameters
        $managementLibraryPath = Get-SharePath $Parameters $physicalMachinesRole.PublicInfo.WindowsUpdateStagingFolder.Path $clusterName
        $managementLibraryPath = Split-Path -Path $managementLibraryPath

        $hostUpdateLogShare = Join-Path $managementLibraryPath 'Logs\HostUpdate'

        if(-not (Test-Path $hostUpdateLogShare))
        {
            Trace-Execution " Create a folder on management file share $hostUpdateLogShare "
            try
            {
                New-Item $hostUpdateLogShare -ItemType Directory -Force | Out-Null
            }
            catch
            {
                throw "Failed to create folder on management file share $hostUpdateLogShare. Error $_"
            }
        }
    }

    return $hostUpdateLogShare
}

# Returns the list of orchestrators that are currently available.
function Get-CurrentOrchestrators
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    # Check if the code is running on DVM
    if($Parameters.Roles["DeploymentMachine"])
    {
        $dvmName = $Parameters.Roles["DeploymentMachine"].PublicConfiguration.Nodes.Node | % Name
        if($env:ComputerName -eq $dvmName)
        {
            $dvmIpAddress = $Parameters.Roles["DeploymentMachine"].PublicConfiguration.Nodes.Node | % IPv4Address
            $orchestrator = New-Object -TypeName psobject -Property @{ Name = $dvmName; IPAddress = $dvmIpAddress }
            return @($orchestrator)
        }
    }
    else
    {
        # Check if we only have one host. In that case the code should be running on the same host or the DVM (if performing bare metal POC)
        $physicalMachinesRole = $Parameters.Roles["BareMetal"].PublicConfiguration
        $allPhysicalHosts = @($physicalMachinesRole.Nodes.Node | % Name)
        if( ($allPhysicalHosts.Count -eq 1) -and ($allPhysicalHosts -eq $env:ComputerName) )
        {
            $orchestrator = New-Object -TypeName psobject -Property @{ Name = $env:ComputerName }
            return @( $orchestrator)
        }
    }

    # If the orchestrator is not the DVM or host, then return ERCS VM information
    $orchestrators = @()
    $virtualMachineNodes = $Parameters.Roles["VirtualMachines"].PublicConfiguration.Nodes
    $ercsNodes = $virtualMachineNodes.Node | where { $_.Role -eq "SeedRingServices"}

    foreach($ercsNode in $ercsNodes)
    {
        $name = $ercsNode.Name
        $ercsIpAddress = ($ercsNode.NICs.NIC.IPv4Address -split "/")[0]
        $orchestrator = New-Object -TypeName psobject -Property @{ Name = $name; IPAddress = $ercsIpAddress}
        $orchestrators += $orchestrator
    }
    return @($orchestrators)
}

# Note: This is a temporary implementation to unblock Image Based update
function Update-JEAEndpointsForUpdate {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    # Update PXE endpoint - Remove this once PXE VM has an updated endpoint.
    # PXE Role
    Trace-Execution "Start - Update module needed by PXEEndpoint on PXE VM."
    $pxeRole = $Parameters.Roles["PXE"].PublicConfiguration
    $pxeServerName = $pxeRole.Nodes.Node.Name

    # PhysicalMachine Role
    $physicalMachinesRole = $Parameters.Roles["BareMetal"].PublicConfiguration
    $allPhysicalHosts = $physicalMachinesRole.Nodes.Node | % Name

    # Skipping nodes which are provided in runtime parameters
    $allPhysicalHosts = Skip-NodesProvidedInRuntimeParameter -Parameters $Parameters -Nodes $allPhysicalHosts

    # VirtualMachine Role
    $virtualMachinesRole = $Parameters.Roles["VirtualMachines"].PublicConfiguration

    $clusterName = Get-ManagementClusterName $Parameters
    $libraryShareNugetStorePath = Get-SharePath $Parameters $virtualMachinesRole.PublicInfo.LibraryShareNugetStoreFolder.Path $clusterName

    $tempNugetDir = Join-Path $env:temp 'AzureStackPXE.Deployment'
    Trace-Execution "Expanding Nuget Microsoft.AzureStack.Solution.Deploy.AzureStackPXE.Deployment at $tempNugetDir"
    Expand-NugetContent -NugetName 'Microsoft.AzureStack.Solution.Deploy.AzureStackPXE.Deployment' `
                        -NugetStorePath $libraryShareNugetStorePath `
                        -SourcePath 'content\Scripts' `
                        -DestinationPath $tempNugetDir

    $sourcePath = "$tempNugetDir\*"
    $destinationPath = "\\$pxeServerName\c$\Program Files\WindowsPowerShell\Modules\Microsoft.AzureStack.Solution.Deploy.AzureStackPXE.Deployment\Scripts"
    Trace-Execution "Copying $sourcePath to $destinationPath"
    New-Item -Path $destinationPath -ItemType Directory -Force -ErrorAction SilentlyContinue
    Copy-Item -Path $sourcePath -Destination $destinationPath -Force
    Remove-Item -Force -Path $tempNugetDir -Recurse

    Trace-Execution "Completed - Update module needed by PXEEndpoint on PXE VM."

    Trace-Execution "Start - Update module needed by NewManagementVMEndpoint on all the hosts"

    $tempNugetDir = Join-Path $env:temp 'NodeUtils_NewManagementVM'
    Expand-NugetContent -NugetName 'Microsoft.AzureStack.Solution.Deploy.Common.NodeUtils' `
                        -NugetStorePath $libraryShareNugetStorePath `
                        -SourcePath 'content\NewManagementVM' `
                        -DestinationPath $tempNugetDir

    foreach ($nodeName in $allPhysicalHosts)
    {
        $sourcePath = "$tempNugetDir\*"
        $destinationPath = "\\$nodeName\c$\Program Files\WindowsPowerShell\Modules\NewManagementVM"
        Trace-Execution "Copying $sourcePath to $destinationPath"
        New-Item -Path $destinationPath -ItemType Directory -Force -ErrorAction SilentlyContinue
        Copy-Item -Path $sourcePath -Destination $destinationPath -Force
    }

    Remove-Item -Force -Path $tempNugetDir -Recurse

    Trace-Execution "Completed - Update module needed by NewManagementVMEndpoint on all the hosts."
}

# Returns credentials needed for various operations during deployment and update.
function Get-DomainCredential
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
    $domainRole = $Parameters.Roles["Domain"].PublicConfiguration
    $securityInfo = $cloudRole.PublicInfo.SecurityInfo
    $domainAdminUser = $securityInfo.DomainUsers.User | ? Role -EQ "DomainAdmin"
    $domainAdminCredential = $Parameters.GetCredential($domainAdminUser.Credential)
    $domainAdminName = $domainAdminCredential.GetNetworkCredential().UserName
    $domainAdminPassword = $domainAdminCredential.GetNetworkCredential().Password
    $domainFqdn = $domainRole.PublicInfo.DomainConfiguration.FQDN
    $domainCredential = New-Credential "$domainFqdn\$domainAdminName" $domainAdminPassword

    return $domainCredential
}

# Returns Temporary Domain Admin credentials.
function Get-TemporaryDomainCredential
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )
    $domainAdminCredential = Get-UserAccountCredential -Parameters $Parameters
    return $domainAdminCredential
}

function Get-UserAccountCredential
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory=$false)]
        [string]
        $UserRole = "DomainAdmin"
    )

    $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
    $domainRole = $Parameters.Roles["Domain"].PublicConfiguration
    $securityInfo = $cloudRole.PublicInfo.SecurityInfo
    $UserAccount = $securityInfo.DomainUsers.User | ? Role -EQ $UserRole
    $UserAccountCredential = $Parameters.GetCredential($UserAccount.Credential)
    $domainName = $domainRole.PublicInfo.DomainConfiguration.DomainName
    if(-not $("$($UserAccountCredential.UserName)" -like "*\*") -and [String]::IsNullOrEmpty($DomainName) -eq $false)
    {
        $UserAccountCredential = New-Credential -UserName "$domainName\$($UserAccountCredential.UserName)" -Password $UserAccountCredential.GetNetworkCredential().Password
    }
    return $UserAccountCredential
}

# Update Windows DISM features based on the configuration of Role.xml
# Including installing features and removiing unused features
function Update-WindowsDismFeature
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $false)]
        [object]
        $WindowsFeature,

        [Parameter(Mandatory = $false)]
        [Switch]
        $Online,

        [Parameter(Mandatory = $false)]
        [string]
        $Path,

        [Parameter(Mandatory = $false)]
        [string]
        $WinSxSPath = "$env:windir\WinSxS"
    )

    Trace-Execution "Update Windows DISM features"

    if ($null -ne $WindowsFeature)
    {
        if ($Online)
        {
            $dismFeatures = (Get-WindowsOptionalFeature -Online).FeatureName
        }
        else
        {
            $dismFeatures = (Get-WindowsOptionalFeature -Path $Path).FeatureName
        }

        if ($null -ne $WindowsFeature.Feature.Name)
        {
            $featuresToInstall = $dismFeatures | Where-Object { $_ -in $WindowsFeature.Feature.Name }
            if ($null -ne $featuresToInstall -and $featuresToInstall.Count -gt 0)
            {
                Trace-Execution "Install Windows DISM features: $featuresToInstall"
                if ($Online)
                {
                    Enable-WindowsOptionalFeature -FeatureName $featuresToInstall -Online -All -Source $WinSxSPath -NoRestart
                }
                else
                {
                    Enable-WindowsOptionalFeature -FeatureName $featuresToInstall -Path $path -All
                }
            }
        }

        if ($null -ne $WindowsFeature.RemoveFeature.Name)
        {
            $featuresToRemove = $dismFeatures | Where-Object { $_ -in $WindowsFeature.RemoveFeature.Name }
            if ($null -ne $featuresToRemove -and $featuresToRemove.Count -gt 0)
            {
                Trace-Execution "Remove unused Windows DISM features: $featuresToRemove"
                if ($Online)
                {
                    Disable-WindowsOptionalFeature -FeatureName $featuresToRemove -Online -NoRestart
                }
                else
                {
                    Disable-WindowsOptionalFeature -FeatureName $featuresToRemove -Path $Path
                }
            }
        }
    }
}

<#
.SYNOPSIS
#### Reference from nuget in 1907
Returns a structured object containing information about each of the exceptions in an update summary
#>

function Read-SummaryXml {
    Param (
        [parameter(Mandatory = $false)][string] $RoutingJsonPath = $RoutingJsonSharePath,
        [parameter(Mandatory = $false, ParameterSetName = 'Path')][string] $SummaryXMLPath,
        [parameter(Mandatory = $false, ParameterSetName = 'Xml')][xml] $SummaryXML,
        [parameter(Mandatory = $false)][switch] $Routing
    )

    if ($SummaryXMLPath)
    {
        $SummaryXML = Get-Content "$SummaryXMLPath" -ErrorAction Stop
    }

    $Exceptions = $SummaryXML.SelectNodes(".//Exception")

    $returnInformation = @()

    foreach ($exception in $Exceptions)
    {
        if ($exception.ParentNode.RolePath)
        {
            $RolePath = $exception.ParentNode.RolePath | select -first 1
            $Interface = $exception.ParentNode.InterfaceType | select -first 1
            $ExecutionContextRolePath = $null
            $ExecutionContextNode = ""
            $ActionType = $null
            $ActionRolePath = ""
            $curAncestor = $exception
            while ($curAncestor -and (!$ExecutionContextRolePath -or !$ActionType))
            {
                if (!$ExecutionContextRolePath)
                {
                    $ExecutionContextRolePath = $curAncestor.ExecutionContext.Roles.Role.RolePath | select -first 1
                    $ExecutionContextNode = $curAncestor.ExecutionContext.Roles.Role.Nodes.Node.Name | select -first 1
                }

                if (!$ActionType)
                {
                    $ActionType = $curAncestor.ActionType
                    $ActionRolePath = $curAncestor.RolePath
                }

                $curAncestor = $curAncestor.ParentNode
            }

            $returnInformation += @{
                'Exception' = $exception.Raw
                'ExecutionContextNode' = $ExecutionContextNode
                'ExecutionContextRolePath' = $ExecutionContextRolePath
                'RolePath' = $RolePath
                'InterfaceType' = $Interface
                'ActionType' = $ActionType
                'ActionRolePath' = $ActionRolePath
                }
        }
    }

    $returnInformation
}

function Get-FailureListFromMainActionPlan
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $runtimeParameters = $null
    $failureList = $null
    if($Parameters.RunInformation -ne $null -and $Parameters.RunInformation.ContainsKey('RuntimeParameter'))
    {
        $runtimeParameters = $Parameters.RunInformation['RuntimeParameter']
    }
    if($runtimeParameters -ne $null -and $runtimeParameters.ContainsKey('FailureSummaryXml'))
    {
        $failureSummaryXml = $runtimeParameters['FailureSummaryXml']
        $failureList = @(Read-SummaryXml -SummaryXML $failureSummaryXml)
    }
    return $failureList
}

<#
.SYNOPSIS
    A generic wrapper function to send telemetry events.
#>

function Send-TelemetryEvent
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [string]
        $ComponentName,

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

        [Parameter(Mandatory=$true)]
        [int]
        $EventVersion,

        [Parameter(Mandatory=$true)]
        [hashtable]
        $EventData
    )

    $ErrorActionPreference = "Stop"
    Trace-Execution "Telemetry event = Component:[$ComponentName], EventName:[$EventName], EventVersion:[$EventVersion], EventData:$($EventData | Out-String)"

    try
    {
        $telemetryPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Fabric.Health.Telemetry.TelemetryReporter"
        $telemetryDll = Join-Path $telemetryPath "lib\net46\Microsoft.AzureStack.Fabric.Health.Telemetry.TelemetryReporter.dll"
        Import-Module -Name $telemetryDll -Verbose:$false -DisableNameChecking
    }
    catch
    {
        Trace-Warning "Error loading telemetry library: $_"
        return
    }

    try
    {
        Trace-Execution "Sending telemetry event."
        Send-AzureStackTelemetryEvent -Component $ComponentName -Name $EventName -Version $EventVersion -TelemetryEventData $EventData -Verbose
        Trace-Execution "Finish sending telemetry event."
    }
    catch
    {
        Trace-Warning "Error sending telemetry event: $_"
    }
}

<#
.SYNOPSIS
    A generic wrapper function checks whether the current update is pnu or not by comparing minor build version.
#>

function Test-IsMonthlyUpdate
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )
    Trace-Execution "Inside Test-IsMonthlyUpdate method."
    $isPnu = $false
    if ((Test-IsUpdate -Parameters $Parameters) -and !(Test-IsHotfixUpdate -Parameters $Parameters))
    {
        $isPnu = $true
    }
    Trace-Execution "Is it a pnu update :: $isPnu."
    return $isPnu
}

<#
.SYNOPSIS
    A generic wrapper function checks whether the current update is a Hotfix pnu or not by checking the Update Name.
#>

function Test-IsHotfixUpdate
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )
    Trace-Execution "Inside Test-IsHotfixUpdate method."
    $isHotfixPNU = $false
    # In case of update, run time information will be populated
    if($Parameters.RunInformation -ne $null)
    {
        $runtimeParameters = $Parameters.RunInformation['RuntimeParameter']
        if( $runtimeParameters -ne $null -and $runtimeParameters.ContainsKey('UpdateVersion') )
        {
            $updateMetadataXml = [xml]$runtimeParameters['metadata']
            Trace-Execution "UpdateName : $($updateMetadataXml.UpdatePackageManifest.UpdateInfo.UpdateName)"
            if($updateMetadataXml.UpdatePackageManifest.UpdateInfo.UpdateName -match 'AzS Hotfix')
            {
                $isHotfixPNU = $true;
            }
        }
    }
    Trace-Execution "Is it a Hotfix Update :: $isHotfixPNU."
    return $isHotfixPNU
}

<#
.SYNOPSIS
    A helper function to check if the current action plan is an Update action plan.
#>

function Test-IsUpdate
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )
    $updateVersion = Get-InProgressUpdateVersion -Parameters $Parameters
    if ($updateVersion -ne $null)
    {
        return $true
    }
    else
    {
        return $false
    }
}

<#
.SYNOPSIS
    Tests whether the execution context node is a member of the management cluster.
#>

function Test-ManagementClusterNode
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters
    )

    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    # Default to true if there is no BareMetal execution context
    $result = $true

    # If there is a BareMetal execution context, compare management cluster name and RefClusterId of the node
    if (
        ($nodeName = Get-ExecutionContextNodeName -Parameters $Parameters) -and
        ((Get-ExecutionContextRoleName -Parameters $Parameters) -eq 'BareMetal')
    )
    {
        $managementClusterName = Get-ManagementClusterName $Parameters
        Trace-Execution "Management cluster name is '$managementClusterName'"
        $bareMetalRole = $Parameters.Roles["BareMetal"].PublicConfiguration
        $nodeClusterName = ($bareMetalRole.Nodes.Node | Where-Object {$_.Name -eq $nodeName}).RefClusterId
        Trace-Execution "Node '$nodeName' cluster is '$nodeClusterName'"
        if ($nodeClusterName -eq $managementClusterName)
        {
            Trace-Execution "Node '$nodeName' is a member of management cluster '$managementClusterName'"
        }
        else
        {
            Trace-Execution "Node '$nodeName' is not a member of management cluster '$managementClusterName'"
            $result = $false
        }
    }

    return $result
}

<#
.SYNOPSIS
    A helper function to Skip nodes which are provided in runtime parameters.
#>

function Skip-NodesProvidedInRuntimeParameter
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters]
        $Parameters,

        [Parameter(Mandatory = $true)]
        [string[]]
        $Nodes
    )

    Trace-Execution "[Skip-NodesProvidedInRuntimeParameter] List of Nodes which are getting filtered $($Nodes -join ',')."

    $unreachableNodesStr = $Parameters.RunInformation['RuntimeParameter']['UnreachableNodes']

    if([string]::IsNullOrEmpty($unreachableNodesStr))
    {
        Trace-Execution "[Skip-NodesProvidedInRuntimeParameter] No nodes are present in the list of unreachable nodes."
        return $Nodes
    }

    Trace-Execution "[Skip-NodesProvidedInRuntimeParameter] List of unreachable nodes: $unreachableNodesStr."

    $unreachableNodes = $unreachableNodesStr -split ','

    $newList = $Nodes | % { $_ -notin $unreachableNodes }

    Trace-Execution "[Skip-NodesProvidedInRuntimeParameter] List of Nodes after Filtering $($newList -join ',')."

    return $newList
}

<#
.SYNOPSIS
    A helper function to get first available node.
#>

function Get-FirstAvailableNode
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [string[]]
        $Nodes
    )

    Trace-Execution "[Get-FirstAvailableNode] List of Nodes: $($Nodes -join ',')."

    foreach($node in $Nodes)
    {
        $returnValue = Invoke-Command {"reachable"} -ComputerName $node -ErrorAction Ignore

        if($returnValue -eq "reachable")
        {
            Trace-Execution "[Get-FirstAvailableNode] Node selected with WinRM connectivity: '$node'."
            return $node
        }
        else
        {
            Trace-Execution "[Get-FirstAvailableNode] Node is not reachable via WinRM: '$node'."
        }
    }

    Trace-Warning "[Get-FirstAvailableNode] No node is reachable via WinRM, fall back to Test-NetConnection (ping)."

    foreach($node in $Nodes)
    {
        $returnValue = Test-NetConnection -ComputerName $node -ErrorAction Ignore

        if($returnValue.PingSucceeded)
        {
            Trace-Execution "[Get-FirstAvailableNode] Node selected with Test-NetConnection connectivity: '$node'."
            return $node
        }
        else
        {
            Trace-Execution "[Get-FirstAvailableNode] Node is not reachable via Test-NetConnection: '$node'."
        }
    }

    # In few situations where this code is running on ECE agent then there may be permission issues, to work that around
    # returning first node if none of the nodes are reachable.
    # TODO: Fix the permission issue with ECE agent
    Trace-Warning "[Get-FirstAvailableNode] Fall back to return first node as No node is reachable from the list: $($Nodes -join ',')."
    return $Nodes[0]
}

<#
.SYNOPSIS
    A helper function to check if the cloud admin operation status is update critical.
#>

function Test-CloudStatusUpdateCritical
{
    $ErrorActionPreference = "Stop"
    Import-Module -Name ECEClient -Verbose:$false -DisableNameChecking

    $eceClient = Create-ECEClientWithServiceResolver
    $eceParamsXml = [XML]($eceClient.GetCloudParameters().getAwaiter().GetResult().CloudDefinitionAsXmlString)

    $statusNode = $eceParamsXml.SelectNodes("//Parameter[@Name='CloudAdminOperationStatus']")
    return ($statusNode.Value -eq "UpdateCritical")
}

function Get-AzureStackHostAllVirtualSwitchNames
{
    Param(
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters] $Parameters
    )

    [System.String[]] $physicalMachines = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node | Select-Object -ExpandProperty "Name"
    [PSObject[]] $vmSwitch = Get-VMSwitch -ComputerName $physicalMachines[0] -SwitchType External

    if ((-not $vmSwitch) -or $vmSwitch.Count -eq 0)
    {
        Trace-Error "Cannot get Virtual Switch Name from [ $($physicalMachines[0]) ]"
    }

    [System.String[]] $retVal = $vmSwitch.Name
    return $retVal
}

function Get-AzureStackHostDefaultVirtualSwitchName
{
    Param(
        [Parameter(Mandatory = $true)]
        [CloudEngine.Configurations.EceInterfaceParameters] $Parameters
    )

    [System.String[]] $allSwitches = Get-AzureStackHostAllVirtualSwitchNames -Parameters $Parameters

    return $allSwitches[0]
}

function Set-TrustedHosts {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [string]
        $hostIp,

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

        [Parameter(Mandatory = $true)]
        [PSCredential]
        $Credential
    )
    try
    {
        Invoke-Command -ComputerName $hostIp -ScriptBlock {
            $trustedHosts = $using:hosts
            $existingTrustedHosts = (Get-Item -Path WSMan:\localhost\Client\TrustedHosts).Value
            Trace-Execution "Existing Trusted Hosts: $existingTrustedHosts."
            if (![string]::IsNullOrEmpty($existingTrustedHosts) -and $existingTrustedHosts -ne "*")
            {
                $trustedHosts = (($existingTrustedHosts.Split(",") + $trustedHosts.Split(",")) | select -uniq) -join ','
            }
            Trace-Execution "Adding Trusted Hosts: $trustedHosts."
            Set-Item WSMan:\localhost\Client\TrustedHosts -Value $trustedHosts -Force
        } -Credential $Credential
    }
    catch
    {
        Trace-Error "Failed to add Trusted Hosts: $hosts on $hostIp with exception. $_"
        throw $_
    }
}

Export-ModuleMember -Function Add-IDnsConfiguration
Export-ModuleMember -Function Add-IPAddress
Export-ModuleMember -Function Add-LoadBalancerToNetworkAdapter
Export-ModuleMember -Function Add-NetworkAdapterToNetwork
Export-ModuleMember -Function ConnectPSSession
Export-ModuleMember -Function ConvertFrom-IPAddress
Export-ModuleMember -Function Convert-IPv4IntToString
Export-ModuleMember -Function Convert-IPv4StringToInt
Export-ModuleMember -Function ConvertTo-IPAddress
Export-ModuleMember -Function ConvertTo-MacAddress
Export-ModuleMember -Function ConvertTo-PrefixLength
Export-ModuleMember -Function ConvertTo-SubnetMask
Export-ModuleMember -Function Expand-DeploymentArtifacts
Export-ModuleMember -Function Expand-NugetContent
Export-ModuleMember -Function Expand-UpdateContent
Export-ModuleMember -Function Get-FirstAvailableNode
Export-ModuleMember -Function Get-AvailableADComputerName
Export-ModuleMember -Function Get-BareMetalCredential
Export-ModuleMember -Function Get-BroadcastAddress
Export-ModuleMember -Function Get-ClusterShare
Export-ModuleMember -Function Get-ClusterShareNames
Export-ModuleMember -Function Get-CurrentOrchestrators
Export-ModuleMember -Function Get-DomainCredential
Export-ModuleMember -Function Get-DomainIPMapping
Export-ModuleMember -Function Get-EndpointAndPort
Export-ModuleMember -Function Get-ExecutionContextClusterName
Export-ModuleMember -Function Get-ExecutionContextNodeName
Export-ModuleMember -Function Get-ExecutionContextRoleName
Export-ModuleMember -Function Get-GatewayAddress
Export-ModuleMember -Function Get-HostUpdateShare
Export-ModuleMember -Function Get-InProgressUpdateVersion
Export-ModuleMember -Function Get-InProgressUpdatePackagePath
Export-ModuleMember -Function Get-InProgressUpdateNugetStore
Export-ModuleMember -Function Get-IsVirtualNetworkAlreadyConfigured
Export-ModuleMember -Function Get-JeaSession
Export-ModuleMember -Function Get-LocalCsvPathFromSharePath
Export-ModuleMember -Function Get-MacAddress
Export-ModuleMember -Function Get-MacAddressString
Export-ModuleMember -Function Get-NCAccessControlList
Export-ModuleMember -Function Get-NCCredential
Export-ModuleMember -Function Get-NCGateway
Export-ModuleMember -Function Get-NCGatewayPool
Export-ModuleMember -Function Get-NCIPPool
Export-ModuleMember -Function Get-NCLoadBalancer
Export-ModuleMember -Function Get-NCLoadbalancerManager
Export-ModuleMember -Function Get-NCLoadBalancerMux
Export-ModuleMember -Function Get-NCLogicalNetwork
Export-ModuleMember -Function Get-NCLogicalNetworkSubnet
Export-ModuleMember -Function Get-NCMACPool
Export-ModuleMember -Function Get-NCNetworkInterface
Export-ModuleMember -Function Get-NCNetworkInterfaceInstanceId
Export-ModuleMember -Function Get-NCNetworkInterfaceResourceId
Export-ModuleMember -Function Get-NCPublicIPAddress
Export-ModuleMember -Function Get-NCServer
Export-ModuleMember -Function Get-NCSwitch
Export-ModuleMember -Function Get-NCVirtualGateway
Export-ModuleMember -Function Get-NCVirtualNetwork
Export-ModuleMember -Function Get-NCVirtualServer
Export-ModuleMember -Function Get-NCVirtualSubnet
Export-ModuleMember -Function Get-NetworkAddress
Export-ModuleMember -Function Get-NetworkDefinitionForCluster
Export-ModuleMember -Function Get-NetworkDefinitions
Export-ModuleMember -Function Get-NetworkMap
Export-ModuleMember -Function Get-NetworkNameForCluster
Export-ModuleMember -Function Get-PortProfileId
Export-ModuleMember -Function Get-RangeEndAddress
Export-ModuleMember -Function Get-ScopeRange
Export-ModuleMember -Function Get-ServerResourceId
Export-ModuleMember -Function Get-SharePath
Export-ModuleMember -Function Get-StorageEndpointName
Export-ModuleMember -Function Get-TemporaryDomainCredential
Export-ModuleMember -Function Get-UserAccountCredential
Export-ModuleMember -Function Initialize-ECESession
Export-ModuleMember -Function Invoke-ECECommand
Export-ModuleMember -Function Invoke-PSDirectOnVM
Export-ModuleMember -Function Invoke-ScriptBlockInParallel
Export-ModuleMember -Function Invoke-ScriptBlockWithRetries
Export-ModuleMember -Function Invoke-WebRequestWithRetries
Export-ModuleMember -Function IsIpPoolRangeValid
Export-ModuleMember -Function IsIpWithinPoolRange
Export-ModuleMember -Function IsOneNode
Export-ModuleMember -Function IsOnVirtualMachine
Export-ModuleMember -Function IsVirtualAzureStack
Export-ModuleMember -Function JSONDelete
Export-ModuleMember -Function JSONGet
Export-ModuleMember -Function JSONPost
Export-ModuleMember -Function Mount-WindowsImageWithRetry
Export-ModuleMember -Function New-ACL
Export-ModuleMember -Function New-Credential
Export-ModuleMember -Function New-ExecutionContextXmlForNode
Export-ModuleMember -Function New-LoadBalancerVIP
Export-ModuleMember -Function New-NCAccessControlList
Export-ModuleMember -Function New-NCAccessControlListRule
Export-ModuleMember -Function New-NCBgpPeer
Export-ModuleMember -Function New-NCBgpRouter
Export-ModuleMember -Function New-NCBgpRoutingPolicy
Export-ModuleMember -Function New-NCBgpRoutingPolicyMap
Export-ModuleMember -Function New-NCCredential
Export-ModuleMember -Function New-NCGateway
Export-ModuleMember -Function New-NCGatewayPool
Export-ModuleMember -Function New-NCGreTunnel
Export-ModuleMember -Function New-NCIPPool
Export-ModuleMember -Function New-NCIPSecTunnel
Export-ModuleMember -Function New-NCL3Tunnel
Export-ModuleMember -Function New-NCLoadBalancer
Export-ModuleMember -Function New-NCLoadBalancerBackendAddressPool
Export-ModuleMember -Function New-NCLoadBalancerFrontEndIPConfiguration
Export-ModuleMember -Function New-NCLoadBalancerLoadBalancingRule
Export-ModuleMember -Function New-NCLoadBalancerMux
Export-ModuleMember -Function New-NCLoadBalancerMuxPeerRouterConfiguration
Export-ModuleMember -Function New-NCLoadBalancerOutboundNatRule
Export-ModuleMember -Function New-NCLoadBalancerProbe
Export-ModuleMember -Function New-NCLoadBalancerProbeObject
Export-ModuleMember -Function New-NCLogicalNetwork
Export-ModuleMember -Function New-NCLogicalNetworkSubnet
Export-ModuleMember -Function New-NCLogicalSubnet
Export-ModuleMember -Function New-NCMACPool
Export-ModuleMember -Function New-NCNetworkInterface
Export-ModuleMember -Function New-NCPublicIPAddress
Export-ModuleMember -Function New-NCServer
Export-ModuleMember -Function New-NCServerConnection
Export-ModuleMember -Function New-NCServerNetworkInterface
Export-ModuleMember -Function New-NCSlbState
Export-ModuleMember -Function New-NCSwitch
Export-ModuleMember -Function New-NCSwitchPort
Export-ModuleMember -Function New-NCVirtualGateway
Export-ModuleMember -Function New-NCVirtualNetwork
Export-ModuleMember -Function New-NCVirtualServer
Export-ModuleMember -Function New-NCVirtualSubnet
Export-ModuleMember -Function New-NCVpnClientAddressSpace
Export-ModuleMember -Function NormalizeIPv4Subnet
Export-ModuleMember -Function PublishAndStartDscConfiguration
Export-ModuleMember -Function PublishAndStartDscForJea
Export-ModuleMember -Function Remove-LoadBalancerFromNetworkAdapter
Export-ModuleMember -Function Remove-NCAccessControlList
Export-ModuleMember -Function Remove-NCCredential
Export-ModuleMember -Function Remove-NCGateway
Export-ModuleMember -Function Remove-NCGatewayPool
Export-ModuleMember -Function Remove-NCIPPool
Export-ModuleMember -Function Remove-NCLoadBalancer
Export-ModuleMember -Function Remove-NCLoadBalancerMux
Export-ModuleMember -Function Remove-NCLogicalNetwork
Export-ModuleMember -Function Remove-NCMACPool
Export-ModuleMember -Function Remove-NCNetworkInterface
Export-ModuleMember -Function Remove-NCPublicIPAddress
Export-ModuleMember -Function Remove-NCServer
Export-ModuleMember -Function Remove-NCSwitch
Export-ModuleMember -Function Remove-NCVirtualGateway
Export-ModuleMember -Function Remove-NCVirtualNetwork
Export-ModuleMember -Function Remove-NCVirtualServer
Export-ModuleMember -Function Remove-PortProfileId
Export-ModuleMember -Function Set-MacAndIPAddressSingleNode
Export-ModuleMember -Function Set-MacAndIPAddress
Export-ModuleMember -Function Set-NCConnection
Export-ModuleMember -Function Set-NCLoadBalancerManager
Export-ModuleMember -Function Set-PortProfileId
Export-ModuleMember -Function Set-PortProfileIdHelper
Export-ModuleMember -Function Send-TelemetryEvent
Export-ModuleMember -Function Skip-NodesProvidedInRuntimeParameter
Export-ModuleMember -Function Test-CloudStatusUpdateCritical
Export-ModuleMember -Function Test-IPConnection
Export-ModuleMember -Function Test-NetworkMap
Export-ModuleMember -Function Test-IsMonthlyUpdate
Export-ModuleMember -Function Test-IsHotfixUpdate
Export-ModuleMember -Function Test-IsUpdate
Export-ModuleMember -Function Test-ManagementClusterNode
Export-ModuleMember -Function Test-PSSession
Export-ModuleMember -Function Test-WSManConnection
Export-ModuleMember -Function Trace-Error
Export-ModuleMember -Function Trace-Execution
Export-ModuleMember -Function Trace-Warning
Export-ModuleMember -Function Update-JEAEndpointsForUpdate
Export-ModuleMember -Function Update-NCCredential
Export-ModuleMember -Function Update-NCServer
Export-ModuleMember -Function Update-NCVirtualServer
Export-ModuleMember -Function Update-WindowsDismFeature
Export-ModuleMember -Function Wait-Result
Export-ModuleMember -Function Wait-VirtualNetwork
Export-ModuleMember -Function Read-SummaryXml
Export-ModuleMember -Function Get-FailureListFromMainActionPlan
Export-ModuleMember -Function Get-AzureStackHostAllVirtualSwitchNames
Export-ModuleMember -Function Get-AzureStackHostDefaultVirtualSwitchName
Export-ModuleMember -Function Set-TrustedHosts

# SIG # Begin signature block
# MIInvwYJKoZIhvcNAQcCoIInsDCCJ6wCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCq7KjTj0Qhr0Br
# fcAa/apM/k33E0XcvQ+h4UD1Pf277qCCDXYwggX0MIID3KADAgECAhMzAAADrzBA
# DkyjTQVBAAAAAAOvMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24xKDAmBgNVBAMTH01pY3Jvc29mdCBDb2RlIFNpZ25p
# bmcgUENBIDIwMTEwHhcNMjMxMTE2MTkwOTAwWhcNMjQxMTE0MTkwOTAwWjB0MQsw
# CQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9u
# ZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMR4wHAYDVQQDExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24wggEiMA0GC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