MSEndpointMgr / ConfigMgr

Microsoft Endpoint Configuration Manager scripts and tools
637 stars 281 forks source link

Invoke-CMDownloadBIOSPackage V3.0.1 beta bug #317

Open MichaelGibsonAltrad opened 3 years ago

MichaelGibsonAltrad commented 3 years ago

We're trying the v3.0.1 beta BIOS download script as we're seeing some weirdness with model detections for both HP and Dell and I wanted to see if this fixes it, and noticed that when multiple packages are returned for a HP (haven't checked other makes yet), the check at line 1151 doesn't work as the PackageList variable created is not an array, so does not have a count method. To fix this you need to wrap the whole command in @() as per the below code changes. This forces the returned value from this Select-Object -First 1 to be an array, so your check at line 1151 which uses .count works.

` if ($ComputerManufacturer -match "Dell") { $PackageList = @($PackageList | Sort-Object -Property SourceDate -Descending | Select-Object -First 1) } elseif ($ComputerManufacturer -eq "Lenovo") { $ComputerDescription = Get-WmiObject -Class Win32_ComputerSystemProduct | Select-Object -ExpandProperty Version

Attempt to find exact model match for Lenovo models which overlap model types

                            $PackageList = @($PackageList | Where-object {
                                ($_.Name -like "*$ComputerDescription") -and ($_.Manufacturer -match $ComputerManufacturer)
                            } | Sort-object -Property SourceDate -Descending | Select-Object -First 1)

                            If ($PackageList -eq $null) {
                                # Fall back to select the latest model type match if no model name match is found
                                $PackageList = @($PackageList | Sort-object -Property SourceDate -Descending | Select-Object -First 1)
                            }
                        } elseif ($ComputerManufacturer -match "Hewlett-Packard|HP") {
                            # Determine the latest BIOS package by creation date
                            $PackageList = @($PackageList | Sort-Object -Property PackageCreated -Descending | Select-Object -First 1)
                        } elseif ($ComputerManufacturer -match "Microsoft") {
                            $PackageList = @($PackageList | Sort-Object -Property PackageCreated -Descending | Select-Object -First 1)
                        }
                        if ($PackageList.Count -eq 1) {

`