MSEndpointMgr / ModernDriverManagement

Official repo of Modern Driver Management from MSEndpointMgr.com
https://www.msendpointmgr.com
MIT License
130 stars 75 forks source link

Bug in script when collating info for $DriverPackageDetails PSObject #284

Open Dusku2099 opened 2 months ago

Dusku2099 commented 2 months ago

Hi,

I've found a bug in this section of script starting at line 1349

foreach ($DriverPackageItem in $DriverPackages) {

Construct custom object to hold values for current driver package properties used for matching with current computer details

        $DriverPackageDetails = [PSCustomObject]@{
            PackageName = $DriverPackageItem.Name
            PackageID = $DriverPackageItem.PackageID
            PackageVersion = $DriverPackageItem.Version
            DateCreated = $DriverPackageItem.SourceDate
            Manufacturer = $DriverPackageItem.Manufacturer
            Model = $null
            _**SystemSKU = $DriverPackageItem.Description.Split(":").Replace("(", "").Replace(")", "")[1]**_
            OSName = $null
            OSVersion = $null
            Architecture = $null
        }

The SystemSKU line is not compatible with MS Surface Laptop 3/4/5's as they contain a ":" within the SKU, the Split cuts off the end of the SKU when reading the package Description, causing a failure to match (MS Surface SKU list for reference https://learn.microsoft.com/en-us/surface/surface-system-sku-reference)

For testing/verification:

The package has the following in the Description field - "(Models included:Surface_Laptop_4_1952:1953)" and the below is what is stored when the $DriverPackageDetails PSObject is constructed:

@{PackageName=Drivers - Microsoft Surface Laptop 4 - Windows 11 21H2 x64; PackageID=ZZZ00001; PackageVersion=24.014.43190.0; DateCreated=2024-05-28T13:06:15Z; Manufacturer=Microsoft; Model=; _SystemSKU=Surface_Laptop_4_1952_; OSName=; OSVersion=; Architecture=}

I bodged in a temporary fix by replacing the line with: SystemSKU = $DriverPackageItem.Description.Replace("Models included:","").Replace("(", "").Replace(")", "") which now successfully stores the correct SKU information.

but this then leads on to the second bug. Surface Laptop 3/4/5's come in Intel and AMD variants with their own driver packs. They are both "Surface Laptop X" for Model type, with the SKU the only differentiator. When running the script with both AMD and Intel driver packs in the environment (running a mix,) I get the below:

so I think the code may need to be updated to account for this possibility.

Hope the above helps, Cheers

Dusku2099 commented 2 months ago

Temporary fix:

Leave rest of script as is, at line 1143, replace the Microsoft switch section with the one below which includes override values for the affected models.


# Gather computer details based upon specific computer manufacturer
        $ComputerManufacturer = (Get-WmiObject -Class "Win32_ComputerSystem" | Select-Object -ExpandProperty Manufacturer).Trim()
        switch -Wildcard ($ComputerManufacturer) {
            "*Microsoft*" {
                $ComputerDetails.Manufacturer = "Microsoft"
                $ComputerDetails.Model = (Get-WmiObject -Class "Win32_ComputerSystem" | Select-Object -ExpandProperty Model).Trim()
                $ComputerDetails.SystemSKU = Get-WmiObject -Namespace "root\wmi" -Class "MS_SystemInformation" | Select-Object -ExpandProperty SystemSKU

                #Hack in work around for Microsoft Surface Laptop variants 

                #Surface Laptop 3 13.5" Intel
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_3_1867:1868"){
                    $ComputerDetails.Model = "Surface Laptop 3 13.5 Intel"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_3_1867"
                }

                #Surface Laptop 4 13.5" AMD
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_4_1958:1959"){
                    $ComputerDetails.Model = "Surface Laptop 4 13.5 AMD"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_4_1958"
                }

                #Surface Laptop 4 13.5" Intel
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_4_1950:1951"){
                    $ComputerDetails.Model = "Surface Laptop 4 13.5 Intel"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_4_1950"
                }

                #Surface Laptop 4 15" AMD
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_4_1952:1953"){
                    $ComputerDetails.Model = "Surface Laptop 4 15 AMD"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_4_1952"
                }

                #Surface Laptop 4 15" Intel
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_4_1978:1979"){
                    $ComputerDetails.Model = "Surface Laptop 4 15 Intel"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_4_1978"
                }

                #Surface Laptop 5 13.5" Consumer
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_5_1950:1951"){
                    $ComputerDetails.Model = "Surface Laptop 5 13.5 Consumer"
                    $ComputerDetails.SystemSKU = "Surface_Laptop_5_1950"
                }

                #Surface Laptop 5 13.5" Commercial
                If ($ComputerDetails.SystemSKU -eq "Surface_Laptop_5_for_Business_1950:1951"){
                    $ComputerDetails.Model = "Surface Laptop 5 13.5 Commercial"
                    $ComputerDetails.SystemSKU = "SSurface_Laptop_5_for_Business_1950"
                }
                    
            }

When creating the Custom Package using DAT, Model should match the override value ("Surface Laptop 5 13.5 Consumer" for example), BaseBoard matches the SystemSKU override value ("Surface_Laptop_5_1950") and that should be enough for it to make a match when the script runs during deployment. Also allows for deployment of Intel and AMD variants without them clashing.