public/Get-LnvUpdate.ps1

# Renamed from Get-LSUpdate.ps1
function Get-LnvUpdate {
    <#
        .SYNOPSIS
        Fetches available driver packages and updates for Lenovo computers
 
        .DESCRIPTION
        Fetches available driver packages and updates for Lenovo computers
 
        .PARAMETER Model
        Specify an alternative Lenovo Computer Model to retrieve update packages for. Use the 4-character Machine Type or the full
        10-character Machine Type and Model (eg. 21XF or 21XFZDVMUS).
        You may want to use this together with '-All' so that packages are not filtered against your local machine's configuration.
 
        .PARAMETER Proxy
        Specifies the URL of a proxy server to use for the connection to the update repository.
 
        .PARAMETER ProxyCredential
        Specifies a user account that has permission to use the proxy server that is specified by the -Proxy
        parameter.
 
        .PARAMETER ProxyUseDefaultCredentials
        Indicates that the cmdlet uses the credentials of the current user to access the proxy server that is
        specified by the -Proxy parameter.
 
        .PARAMETER All
        Return all packages, regardless of whether they are applicable to this specific machine or whether they are already installed.
        E.g. this will return LTE-Modem drivers even on machines that do not have the optional LTE-Modem installed, or 32-bit drivers
        on a 64-bit OS. Attempting to install such inapplicable drivers will likely fail. Re-installing an already installed driver can
        sometimes be useful to fix a driver that got corrupted.
 
        .PARAMETER IncludePhantomDevices
        Consider currently disconnected (phantom) devices as well when evaluating relevant packages.
 
        .PARAMETER ScratchDirectory
        The path to a directory where temporary files are downloaded to for use during the search for packages. These files are cleaned
        up automatically. Defaults to $env:TEMP.
 
        .PARAMETER Repository
        The path to a package repository. This can either be an HTTP(S) URL pointing to a webserver or a filesystem path to a directory.
 
        .PARAMETER MachineCharacteristicsOverride
        Advanced usage: Pass a Hashtable to override information about the computer that is used to evaluate packages.
 
        .PARAMETER NoTestApplicable
        Do not check whether packages are applicable to the computer. The IsApplicable property of the package objects will be set to $null.
        This switch is only available together with -All.
 
        .PARAMETER NoTestInstalled
        Do not check whether packages are already installed on the computer. The IsInstalled property of the package objects will be set to $null.
        This switch is only available together with -All.
 
        .PARAMETER NoTestSeverityOverride
        Packages have a static severity classification, but may also contain a set of tests pertaining to currently installed hardware or drivers
        that, when passed, dynamically override and adjust the severity rating of a package up or down. By default, this module makes a best effort
        to parse, understand and check these. Use this parameter to skip all SeverityOverride tests instead and have all packages be returned with
        their static, default severity classification. This switch is available both with and without -All.
 
        .PARAMETER FailUnsupportedDependencies
        Lenovo specifies different tests with each package to determine whether it is applicable to a machine or not.
        This module makes a best effort to parse, understand and check these.
        However, new kinds of tests may be added by Lenovo at any point and some currently in use are not supported yet either.
        By default, any unknown applicability tests will be treated as passed which may result in a package that is really not applicable being classified as applicable.
        This switch will make all unsupported applicability tests fail instead, which in turn could lead to an applicable package being detected as not applicable instead.
 
        .PARAMETER PassUnsupportedInstallTests
        Lenovo specifies different tests with each package to determine whether it is already installed or not.
        This module makes a best effort to parse, understand and check these.
        However, new kinds of tests may be added by Lenovo at any point and some currently in use are not supported yet either.
        By default, any unknown install tests will be treated as failed which may result in a package that is already installed being classified as missing.
        This switch will make all unsupported install tests pass instead, which in turn could lead to a missing update being detected as installed instead.
 
        .PARAMETER LogFile
        Record this run as a PowerShell transcript in the default log directory
        ($env:ProgramData\Lenovo\Lenovo.Client.Update\Logs). The transcript holds what the console
        showed: the packages that were returned, and the execution time.
 
        .PARAMETER DetailedLog
        Write the detection log, to the default log directory unless -LogPath says otherwise. The
        log starts with a header stating the module version and the exact Windows version of the
        machine, and then records for every package whether it is needed, already installed, or
        which dependency tests it did not meet, with the test results that decided it.
 
        Using this together with -LogFile writes both logs: the transcript and the detection log
        are separate files, so neither switch cancels the other out.
 
        .PARAMETER LogPath
        The file or directory to write the log to, instead of the default log directory. Used on
        its own it writes a transcript. When both switches are used and -LogPath names a single
        file, that file takes the transcript and the detection log is written beside it.
 
        .PARAMETER ExplainDependencies
        Attach the detailed result of every applicability and install test to the returned package
        objects, as the DependencyTests and InstallTests properties. Used by Debug-LnvUpdate.
        The tests are always recorded when -DetailedLog is used, this switch only additionally
        exposes them to the caller.
 
        .EXAMPLE
        # Get available updates for the local computer
        PS> Get-LenovoUpdate
 
        .EXAMPLE
        # Get all available packages for a different computer model
        PS> Get-LenovoUpdate -Model 20K70000GE -All
 
        .EXAMPLE
        # Get available updates and keep both logs in the default log directory
        PS> Get-LnvUpdate -LogFile -DetailedLog
    #>


    [CmdletBinding()]
    [OutputType([Lenovo.Client.Update.LenovoPackage])]
    Param (
        [string]$Model,
        [Uri]$Proxy = $script:LnvUpdateConfiguration.Proxy,
        [PSCredential]$ProxyCredential = $script:LnvUpdateConfiguration.ProxyCredential,
        [switch]$ProxyUseDefaultCredentials = $script:LnvUpdateConfiguration.ProxyUseDefaultCredentials,
        [switch]$All,
        [switch]$IncludePhantomDevices,
        [System.IO.DirectoryInfo]$ScratchDirectory = $env:TEMP,
        [string]$Repository = 'https://download.lenovo.com/catalog',
        [Hashtable]$MachineCharacteristicsOverride = @{},
        [switch]$NoTestApplicable,
        [switch]$NoTestInstalled,
        [switch]$NoTestSeverityOverride,
        [switch]$FailUnsupportedDependencies,
        [switch]$PassUnsupportedInstallTests,
        [Parameter()]
        [ValidateSet('Active', 'Test', 'All')]
        [string]$StatusMode = 'Active',
        [string]$LogPath,
        [switch]$LogFile,
        [switch]$DetailedLog,
        [Parameter(Mandatory=$false)]
        [switch]$SkipSignatureCheck,
        [switch]$ExplainDependencies
    )

    begin {

        $PreviousLogPath = $script:LnvLogFilePath
        $TranscriptFile = $null
        $DetailedLogFile = $null
        [bool]$UseTranscript = $false

        # This block throws on unusable input (unknown model, bad repository) and when it does, the
        # end block never runs.
        trap {
            if ($UseTranscript) {
                try {
                    Stop-Transcript | Out-Null
                } catch {
                    Write-Error "Could not stop transcript: $($_.Exception.Message)"
                    # Nothing to do: this path is already unwinding an error
                }
            }
            $script:LnvLogFilePath = $PreviousLogPath
            break
        }



        $WantTranscript = $LogFile -or ($LogPath -and -not $DetailedLog)

        # -LogFile is passed on only when there is no -LogPath to honour: the switches decide which
        # logs are written and -LogPath decides where they go, so the two never conflict here.
        if ($WantTranscript) {
            $TranscriptFile = Resolve-LnvLogFilePath -LogFile:(-not $LogPath) -LogPath $LogPath -Prefix 'Detection'
        }

        if ($DetailedLog) {
            $DetailedLogFile = Resolve-LnvLogFilePath -LogFile:(-not $LogPath) -LogPath $LogPath -Prefix 'DetailedLog'
        }

        if ($TranscriptFile -and $DetailedLogFile -and $TranscriptFile -eq $DetailedLogFile) {

            $DetailedLogFile = Join-Path -Path (Split-Path -Path $DetailedLogFile -Parent) -ChildPath (
                '{0}-DetailedLog{1}' -f [System.IO.Path]::GetFileNameWithoutExtension($DetailedLogFile),
                                        [System.IO.Path]::GetExtension($DetailedLogFile)
            )
            Write-Warning "-LogPath names a single file but both logs were requested. Writing the detection log to '$DetailedLogFile' instead."
        }

        # If logging is enabled, set it up
        if ($DetailedLogFile) {
            try {

                $null = New-Item -ItemType File -Path $DetailedLogFile -Force -ErrorAction Stop
            } catch {
                Write-Warning "Could not create the log file '$DetailedLogFile': $($_.Exception.Message)"
                $DetailedLogFile = $null
            }

            if ($DetailedLogFile) {
                Write-Information "Logging to: $DetailedLogFile" -InformationAction Continue

                # From here on Write-LnvLog appends to the log file
                $script:LnvLogFilePath = $DetailedLogFile
                Write-LnvLogEnvironmentHeader -Component 'Get-LnvUpdate'
            }
        }

        # Started after the detection log so that the transcript does not open with a line about
        # the other file
        if ($TranscriptFile) {
            $OriginalDebugPreference = $DebugPreference
            $OriginalVerbosePreference = $VerbosePreference

            try {
                Start-Transcript -Path $TranscriptFile -Force -ErrorAction Stop | Out-Null
                $UseTranscript = $true
                Write-Information "Logging to: $TranscriptFile" -InformationAction Continue
            } catch {
                Write-Error "Could not start transcript: $($_.Exception.Message)"
                $TranscriptFile = $null
            }

            if ($UseTranscript) {
                $DebugPreference = if ($PSBoundParameters['Debug']) { 'Continue' } else { 'SilentlyContinue' }
                $VerbosePreference = if ($PSBoundParameters['Verbose']) { 'Continue' } else { 'SilentlyContinue' }
            }
        }

        # Recording which tests passed or failed costs nothing worth measuring, so it is done for
        # every run that produces a log file - that detail is the point of the log.
        [bool]$CollectTrace = $ExplainDependencies -or [bool]$script:LnvLogFilePath

        if ($PSBoundParameters['Debug'] -and $DebugPreference -eq 'Inquire') {
            Write-Verbose "Adjusting the DebugPreference to 'Continue'."
            $DebugPreference = 'Continue'
        }

        if (($NoTestApplicable -or $NoTestInstalled) -and -not $All) {
            throw "You can only use -NoTestApplicable or -NoTestInstalled together with -All"
        }

        if (-not $Model) {
            $Model = (Get-CimInstance -ClassName CIM_ComputerSystem -ErrorAction SilentlyContinue -Verbose:$false).Model
        }

        $Model = $Model.Trim()

        if ($Model.Length -gt 5) {
            $Model = $Model.Substring(0, 4)
        }

        if ($Model -notmatch '^\w{4,5}$') {
            throw "Could not parse computer model number. This may not be a Lenovo computer, or an unsupported model."
        }

        Write-Verbose "Lenovo Model is: $Model"


        Write-LnvLog "Model: $Model | Repository: $Repository | StatusMode: $StatusMode"
        $EnabledSwitches = @(
            'All', 'IncludePhantomDevices', 'NoTestApplicable', 'NoTestInstalled', 'NoTestSeverityOverride',
            'FailUnsupportedDependencies', 'PassUnsupportedInstallTests', 'SkipSignatureCheck', 'ExplainDependencies'
        ).Where({ $PSBoundParameters[$_] })
        Write-LnvLog "Switches: $(if ($EnabledSwitches) { $EnabledSwitches -join ', ' } else { '<none>' })"

        if (-not (Test-RunningAsAdmin)) {
            Write-LnvWarning "Unfortunately, this command produces most accurate results when run as an Administrator`r`nbecause some of the commands Lenovo uses to detect your computers hardware have to run as admin :("
        }

        $RepositoryInfo = Get-PackagePathInfo -Path $Repository
        if (-not $RepositoryInfo.Valid) {
            throw "Repository '${Repository}' refers to an invalid location: $($RepositoryInfo.ErrorMessage)"
        }

        $UTF8ByteOrderMark = [System.Text.Encoding]::UTF8.GetString(@(195, 175, 194, 187, 194, 191))

        New-Variable -Name CachedHardwareTable -Option AllScope, ReadOnly -Value (
            $script:CachedHardwareTable = [MachineCharacteristics]::new($IncludePhantomDevices, $MachineCharacteristicsOverride)
        )

        # Create a random subdirectory inside ScratchDirectory and use that instead, so we can safely delete it later without taking user data with us
        do {
            $ScratchSubDirectory = Join-Path -Path $ScratchDirectory -ChildPath ( [System.IO.Path]::GetRandomFileName() )
        } until (-not (Test-Path -Path $ScratchSubDirectory))
        # Using the FullName path returned by New-Item ensures we have an absolute path even if the ScratchDirectory passed by the user was relative.
        # This is important because $PWD and System.Environment.CurrentDirectory can differ in PowerShell, so not all path-related APIs/Cmdlets treat relative
        # paths as relative to the same base-directory which would cause errors later, particularly during path resolution in Split-ExecutableAndArguments
        try {
            # throw is needed to really stop and exit the whole script/cmdlet on an error, ErrorAction Stop would only terminate the current pipeline/statement
            $ScratchSubDirectory = New-Item -Path $ScratchSubDirectory -Force -ItemType Directory -ErrorAction Stop | Select-Object -ExpandProperty FullName
        }
        catch {
            throw $_
        }

        Write-Verbose "Created temporary scratch directory: $ScratchSubDirectory"

        [array]$PackagePointers = Get-PackagesInRepository -Repository $Repository -RepositoryType $RepositoryInfo.Type -Model $Model -StatusMode $StatusMode

        if ($PackagePointers.Count -eq 0) {
            if ($StatusMode -ne 'All') {
                Write-LnvWarning "No packages found with status '$StatusMode' for model '$Model' in repository '$Repository'"
            } else {
                throw "No packages for computer model '${Model}' could be retrieved from repository '${Repository}'"
            }
        }

        Write-Verbose "Processing $($PackagePointers.Count) packages"
        Write-LnvLog "Found $($PackagePointers.Count) package definitions to evaluate"

        # This variable will hold the LenovoPackage objects as they are processed in two stages
        New-Variable -Name PackageList -Option Private -Value ( [System.Collections.Generic.List[Lenovo.Client.Update.LenovoPackage]]::new() )

        # This variable will hold additional metadata that needs to be referenced from nested scopes (functions) during dependency tests
        New-Variable -Name AllPackagesDependenciesInfo -Option AllScope, ReadOnly -Value ( [System.Collections.Generic.Dictionary[string, Lenovo.Client.Update.PackageDependenciesInfo]]::new() )


        New-Variable -Name NoInstallTestIDs -Option Private -Value ( [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase) )
        $detectionStartTime = Get-Date
    }

    process {
        # Stage 1 of 2 : Process most parts of the packages XML, only dependencies will be resolved later to support Coreq (package inter-dependency) tests
        :NextPackage foreach ($Package in $PackagePointers) {
            Write-Verbose "Processing package $($Package.AbsoluteLocation)"

            # Creata a random subdirectory for the packages temporary files
            do {
                $LocalPackageRoot = Join-Path -Path $ScratchSubDirectory -ChildPath ( [System.IO.Path]::GetRandomFileName() )
            } until (-not (Test-Path -Path $LocalPackageRoot))
            # Using the FullName path returned by New-Item ensures we have an absolute path even if the ScratchDirectory passed by the user was relative.
            # This is important because $PWD and System.Environment.CurrentDirectory can differ in PowerShell, so not all path-related APIs/Cmdlets treat relative
            # paths as relative to the same base-directory which would cause errors later, particularly during path resolution in Split-ExecutableAndArguments
            try {
                $LocalPackageRoot = New-Item -Path $LocalPackageRoot -Force -ItemType Directory -ErrorAction Stop | Select-Object -ExpandProperty FullName
            }
            catch {
                Write-LnvError "Could not create the temporary package directory '$LocalPackageRoot', continuing with the next package."
                continue
            }

            Write-Debug "Local package scratch directory: $LocalPackageRoot"

            # Packages like https://download.lenovo.com/pccbbs/mobiles/r0qch05w_2_.xml show we have to download the XML itself too
            $SpfParams = @{
                'SourceFile' = $Package
                'Directory' = $LocalPackageRoot
                'Proxy' = $Proxy
                'ProxyCredential' = $ProxyCredential
                'ProxyUseDefaultCredentials' = $ProxyUseDefaultCredentials
            }
            try{
            [string]$localFile = Save-PackageFile @SpfParams
            }
            catch {
                if ($_.Exception.Message -like "*404*") {
                    Write-LnvWarning "Package $($Package.Name) returned 404 (file not found on Lenovo server), skipping"
                }else{
                    Write-LnvError "The package $($Package.Name) could not be retrieved: $($_.Exception.Message) and will be skipped"
                }
                Continue
            }

            if ([string]::IsNullOrEmpty($localFile)) {
                Write-LnvWarning "Package $($Package.Name) could not be downloaded, skipping"
                continue
            }
            $rawPackageXML = Get-Content -LiteralPath $localFile -Raw -ErrorAction Ignore
            if (-not $?) {
                Write-LnvError "The package $($Package.Name) could not be retrieved or read and will be skipped"
                continue
            }

            try {
                [xml]$packageXML = $rawPackageXML -replace "^$UTF8ByteOrderMark"
            }
            catch {
                if ($_.FullyQualifiedErrorId -eq 'InvalidCastToXmlDocument') {
                    Write-LnvWarning "Could not parse package '$($Package.Name)' (invalid XML)"
                } else {
                    Write-LnvWarning "Could not parse package '$($Package.Name)':`r`n$($_.Exception.Message)"
                }
                continue
            }

            $PackageFiles = [System.Collections.Generic.List[Lenovo.Client.Update.PackageFilePointer]]::new()
            $PackageFiles.Add($Package)
            $packageXML.Package.Files.SelectNodes('descendant-or-self::File') | Foreach-Object {
                $FileInfo = Get-PackagePathInfo -Path $_.Name -BasePath $Package.Container -ForceBasePathIfRelative
                # Cloud/Hybrid repository: a file (typically the installer payload) is intentionally
                # not stored locally. Fall back to the Lenovo download base recorded in database.xml
                # so the file resolves to its cloud URL instead of being reported as missing.
                if (-not $FileInfo.Valid -and $Package.CloudInstallerBaseUrl) {
                    $FileInfo = Get-PackagePathInfo -Path $_.Name -BasePath $Package.CloudInstallerBaseUrl -ForceBasePathIfRelative
                }
                if ($FileInfo.Valid) {
                    $PackageFiles.Add(
                        [Lenovo.Client.Update.PackageFilePointer]::new(
                            $_.Name,
                            $FileInfo.AbsoluteLocation,
                            $FileInfo.Type,
                            $_.ParentNode.SchemaInfo.Name,
                            $_.CRC,
                            $_.Size
                        )
                    )
                } else {
                    Write-LnvError "The file '$($_.Name)' referenced by package $($packageXML.Package.id) could not be found or accessed and will be ignored"
                }
            }

            # signature verification for The packages. verify unless -SkipSignatureCheck is specified.
            $PackageIsSigned = $null
            if (-not $SkipSignatureCheck) {
                $PackageIsSigned = $true
                $SignableExtensions = @('.exe','.dll','.xml','.sys','.inf','.msi')
                $DetectionKinds = @('XmlDefinition', 'External')
                foreach ($pf in $PackageFiles | Where-Object {
                        $DetectionKinds -contains $_.Kind -and
                        $SignableExtensions -contains [System.IO.Path]::GetExtension($_.Name).ToLower() }) {
                    $spf = @{
                        'SourceFile' = $pf
                        'Directory' = $LocalPackageRoot
                        'Proxy' = $Proxy
                        'ProxyCredential' = $ProxyCredential
                        'ProxyUseDefaultCredentials' = $ProxyUseDefaultCredentials
                    }
                    try {
                        [string]$fileLocal = Save-PackageFile @spf
                    } catch {
                        Write-Verbose "Could not download detection file '$($pf.Name)' for package $($packageXML.Package.id) to verify signature: $($_.Exception.Message)"
                        continue
                    }

                    if (-not $fileLocal -or -not (Test-Path -LiteralPath $fileLocal)) {
                        continue
                    }
                    try {
                        $includeCatalog = $pf.Name -match '\.(inf|sys|xml)$'
                        $signatureResults = @(Test-LnvSignature -Path $fileLocal -IncludeCatalog:$includeCatalog -ErrorAction Stop)

                        if ($signatureResults -contains $false) {
                            Write-LnvWarning "File '$($pf.Name)' in package $($packageXML.Package.id) is not signed by Lenovo"
                            $PackageIsSigned = $false
                        }
                    } catch {
                        Write-Verbose "Signature check failed for $fileLocal $($_.Exception.Message)"
                        $PackageIsSigned = $false
                    }
                }
                # Skip package if any file is unsigned
                if ($PackageIsSigned -eq $false) {
                    Write-LnvWarning "Package $($packageXML.Package.id) contains unsigned files and will be excluded. Use -SkipSignatureCheck to include it."
                    continue NextPackage
                }
            }

            # Download the files needed by external detection tests in package
            if (-not ($NoTestApplicable -and $NoTestInstalled)) {
                foreach ($externalFile in $PackageFiles.Where{ $_.Kind -eq 'External'}) {
                    $SpfParams = @{
                        'SourceFile' = $externalFile
                        'Directory' = $LocalPackageRoot
                        'Proxy' = $Proxy
                        'ProxyCredential' = $ProxyCredential
                        'ProxyUseDefaultCredentials' = $ProxyUseDefaultCredentials
                    }
                    try{
                    $null = Save-PackageFile @SpfParams
                    }catch {
                        if( $_.Exception.Message -like "*404*"){
                            Write-LnvWarning "External file '$($externalFile.Name)' needed for detection tests in package $($packageXML.Package.id) returned 404 (file not found on Lenovo server), skipping"
                        }
                    }
                }
            }

            [string]$PackageTitle = $packageXML.Package.Title.Desc.'#text'

            # Assigned in a statement, not as the result of an if-expression: an empty collection
            # returned from a script block is unrolled by the pipeline and would arrive as $null.
            $InstallTestTrace = $null
            if ($CollectTrace) {
                $InstallTestTrace = [System.Collections.Generic.List[object]]::new()
            }

            # The explicit $null is to avoid powershell/powershell#13651
            [Nullable[bool]]$PackageIsInstalled = if ($NoTestInstalled) {
                $null
            } else {
                if ($packageXML.Package.DetectInstall) {
                    Write-Verbose "Detecting install status of package: $($packageXML.Package.id) ($PackageTitle)"
                    Resolve-XMLDependency -XMLIN $packageXML.Package.DetectInstall -TreatUnsupportedAsPassed:$PassUnsupportedInstallTests -PackagePath $LocalPackageRoot -Trace $InstallTestTrace
                } else {
                    Write-Verbose "Package $($packageXML.Package.id) doesn't have a DetectInstall section"
                    0
                }
            }


            if ($PackageIsInstalled -eq $true) {
                Write-LnvLog "Already installed: $($packageXML.Package.id) '$PackageTitle' version $($packageXML.Package.version) - proven by the DetectInstall tests below"

                foreach ($TraceLine in (Format-LnvDependencyTrace -Trace $InstallTestTrace -PassedOnly)) {
                    Write-LnvLog -Level Detail -Message " $TraceLine"
                }
            } elseif ($PackageIsInstalled -eq $false -and -not $packageXML.Package.DetectInstall) {
                $null = $NoInstallTestIDs.Add($packageXML.Package.id)
            }

            [Lenovo.Client.Update.Severity]$PackageSeverity = $packageXML.Package.Severity.type
            if (-not $NoTestSeverityOverride -and
                $packageXML.Package.SelectSingleNode('SeverityOverride') -and # SeverityOverride element may not exist
                $packageXML.Package.SelectSingleNode('SeverityOverride').HasChildNodes -and # SeverityOverride element may exist but be empty (#63)
                ($packageXML.Package.SeverityOverride.type -ne $packageXML.Package.Severity.type)) {
                Write-Verbose "Parsing severity override for package: $($packageXML.Package.id) ($($packageXML.Package.Title.Desc.'#text'))"
                if (Resolve-XMLDependency -XMLIN $packageXML.Package.SeverityOverride -TreatUnsupportedAsPassed:$true -PackagePath $LocalPackageRoot -FailInboxDrivers) {
                    Write-Debug "Default severity $($packageXML.Package.Severity.type) overriden with $($packageXML.Package.SeverityOverride.type)"
                    [Lenovo.Client.Update.Severity]$PackageSeverity = $packageXML.Package.SeverityOverride.type
                }
            }

            # Calculate package size
            [Int64]$PackageSize = 0
            $PackageFiles | Where-Object { $_.Kind -ne 'External'} | Foreach-Object {
                [Int64]$Number = 0
                $null = [Int64]::TryParse($_.Size, [ref]$Number)
                $PackageSize += $Number
            }

            $packageObject = [Lenovo.Client.Update.LenovoPackage]@{
                'ID'           = $packageXML.Package.id
                'Name'         = $packageXML.Package.name
                'Title'        = $packageXML.Package.Title.Desc.'#text'
                'Type'         = $packageXML.Package.PackageType.type
                'Category'     = $Package.Category
                'Version'      = if ([Version]::TryParse($packageXML.Package.version, [ref]$null)) { $packageXML.Package.version } else { '0.0.0.0' }
                'Severity'     = $PackageSeverity
                'ReleaseDate'  = [DateTime]::ParseExact($packageXML.Package.ReleaseDate, 'yyyy-MM-dd', [CultureInfo]::InvariantCulture, 'None')
                'RebootType'   = $packageXML.Package.Reboot.type
                'Status'       = $Package.Status
                'Vendor'       = $packageXML.Package.Vendor
                'Size'         = $PackageSize
                'URL'          = $Package.AbsoluteLocation
                'Files'        = $PackageFiles
                'Extracter'    = $packageXML.Package
                'Installer'    = [Lenovo.Client.Update.PackageInstallInfo]::new($packageXML.Package)
                'IsApplicable' = $null # Package applicability is determined later in stage 2
                'IsInstalled'  = $PackageIsInstalled
            }

            if ($ExplainDependencies) {
                # LenovoPackage is a compiled type that cannot carry extra fields, so the traces are
                # attached as note properties for Debug-LnvUpdate to report on.
                Add-Member -InputObject $packageObject -MemberType NoteProperty -Name 'InstallTests' -Value $InstallTestTrace -Force
            }

            $PackageList.Add($packageObject)

            if ($AllPackagesDependenciesInfo.ContainsKey($packageXML.Package.name)) {
                Write-Debug "Replacing previous package dependency info for $($packageXML.Package.name)"
            }
            $AllPackagesDependenciesInfo[$packageXML.Package.name] = [Lenovo.Client.Update.PackageDependenciesInfo]@{
                'Version'          = $packageXML.Package.version
                'IsInstalled'      = $PackageIsInstalled
                'Dependencies'     = $packageXML.Package.Dependencies
                'LocalPackageRoot' = $LocalPackageRoot
            }
        }
        # Stage 2 of 2 : Process package dependencies (determines IsApplicable)
        foreach ($Package in $PackageList) {
            $CurrentPackageDependenciesInfo = $AllPackagesDependenciesInfo[$Package.Name]


            $DependencyTrace = $null
            if ($CollectTrace) {
                $DependencyTrace = [System.Collections.Generic.List[object]]::new()
            }

            # The explicit $null is to avoid powershell/powershell#13651
            [Nullable[bool]]$PackageIsApplicable = if ($NoTestApplicable) {
                $null
            } else {
                Write-Verbose "Parsing dependencies for package: $($Package.ID) ($($Package.Title))"
                Resolve-XMLDependency -XMLIN $CurrentPackageDependenciesInfo.Dependencies -TreatUnsupportedAsPassed:(-not $FailUnsupportedDependencies) -PackagePath $CurrentPackageDependenciesInfo.LocalPackageRoot -Trace $DependencyTrace
            }

            $Package.IsApplicable = $PackageIsApplicable

            if ($ExplainDependencies) {
                Add-Member -InputObject $Package -MemberType NoteProperty -Name 'DependencyTests' -Value $DependencyTrace -Force
            }

            # Record why a package was dropped as not applicable.

            if ($PackageIsApplicable -eq $false) {
                # A package can be detected as installed and still fail its dependency tests.

                $NotApplicableIntro = if ($Package.IsInstalled -eq $true) {
                    "Not applicable: $($Package.ID) '$($Package.Title)' version $($Package.Version) - reported as installed above, but the machine does not meet these dependency tests:"
                } else {
                    "Not applicable: $($Package.ID) '$($Package.Title)' version $($Package.Version) - the following dependency tests were not met:"
                }
                Write-LnvLog $NotApplicableIntro
                foreach ($TraceLine in (Format-LnvDependencyTrace -Trace $DependencyTrace -FailedOnly)) {
                    Write-LnvLog -Level Detail -Message " $TraceLine"
                }
            } elseif ($PackageIsApplicable -and $Package.IsInstalled -eq $false) {

                $InstallStatusNote = if ($NoInstallTestIDs.Contains($Package.ID)) {
                    ' - install status unknown, the package has no DetectInstall section'
                } else {
                    ''
                }
                Write-LnvLog "Update needed: $($Package.ID) '$($Package.Title)' version $($Package.Version) [$($Package.Type), severity $($Package.Severity), released $($Package.ReleaseDate.ToString('yyyy-MM-dd'))]$InstallStatusNote"
            }

            if ($All -or ($Package.IsApplicable -and $Package.IsInstalled -eq $false)) {
                $Package
            }
        }
    }

    end {
        $detectionEndTime = Get-Date
        $executionTime = $detectionEndTime - $detectionStartTime

        if ($script:LnvLogFilePath) {

            $InstalledCount     = @($PackageList | Where-Object { $_.IsInstalled -eq $true }).Count
            $NotApplicableCount = @($PackageList | Where-Object { $_.IsApplicable -eq $false -and $_.IsInstalled -ne $true }).Count
            $NeededCount        = @($PackageList | Where-Object { $_.IsApplicable -eq $true -and $_.IsInstalled -eq $false }).Count

            # -NoTestInstalled / -NoTestApplicable leave a package in none of the three
            $UnevaluatedCount = $PackageList.Count - ($NeededCount + $InstalledCount + $NotApplicableCount)

            $Summary = "Evaluated $($PackageList.Count) of $($PackagePointers.Count) package definitions: $NeededCount needed, $InstalledCount already installed, $NotApplicableCount not applicable"
            if ($UnevaluatedCount -gt 0) {
                $Summary += ", $UnevaluatedCount not tested"
            }

            # Not -Always: under Debug-LnvUpdate -ID these counts describe the whole repository
            Write-LnvLog -NoTimestamp -Message ('-' * 78)
            Write-LnvLog "Detection complete in $([math]::Round($executionTime.TotalSeconds, 1)) seconds"
            Write-LnvLog $Summary
            Write-LnvLog -NoTimestamp -Message ('=' * 78)
        }

        $LogsWritten = @($TranscriptFile, $DetailedLogFile).Where({ $_ })

        if ($LogsWritten) {
            if ($UseTranscript) {
                $DebugPreference = $OriginalDebugPreference
                $VerbosePreference = $OriginalVerbosePreference
            }


            Write-Information "Detection Complete" -InformationAction Continue
            Write-Information "Execution Time: $($executionTime.TotalSeconds) seconds" -InformationAction Continue
            foreach ($Written in $LogsWritten) {
                Write-Information "Log saved to: $Written" -InformationAction Continue
            }

            if ($UseTranscript) {
                try {
                    Stop-Transcript | Out-Null
                } catch {
                    Write-Warning "Transcript might not be running."
                }
            }
        }

        $script:LnvLogFilePath = $PreviousLogPath

        Write-Verbose "Cleaning up temporary scratch directory"
        Remove-Item -LiteralPath $ScratchSubDirectory -Recurse -Force -Confirm:$false
    }
}
# SIG # Begin signature block
# MIItugYJKoZIhvcNAQcCoIItqzCCLacCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBg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