Search code examples
powershelldriversccm

Why am I getting incorrect driver classes in SCCM with my PowerShell script?


SCCM Version: 2012 R2
PowerShell Version: 3
Operating System: Windows Server 2008 R2 SP1

I've written a script to create driver packs in SCCM using only signed hard drive controller (HDC) and network (NET) driver classes but I'm getting all sorts of drivers showing up in SCCM.

problem description

I'm hoping this is not posted the wrong place as this issue will require knowledge of both SCCM and PowerShell.

Here is the script:

#Vars
$site = "SITENAME:"
$configMgrCmdLets = "D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
$DriverPackagePath = "\\ServerName\sources\DriverPacks\PE\SignedBootDrivers"
$DriverPackageName = "Signed Boot Drivers"
$MaxQueryResults = 4000

#pre-reqs
Import-Module $configMgrCmdLets

Set-Location $site
if (get-cmSite)
{
    #all good, let's proceed.
    Set-CMQueryResultMaximum -Maximum $MaxQueryResults

    #Does the driverpackage already exist? If not, Create it.
    if (!(Get-cmDriverPackage -Name $DriverPackageName))
    {
        New-CMDriverPackage -Name $DriverPackageName -Path $DriverPackagePath -PackageSourceType StorageDirect
    }


    $drivers = Get-CMDriver | Where-Object `
    {
        $_.IsSuperseded -eq $false `
            -and $_.IsEnabled -eq $true `
            -and $_.IsHidden -eq $false `
            -and $_.DriverSigned -eq $true `
            -and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net") `
            -and $_.SDMPackageXML -match "x64 Windows 8"
    }

    ForEach ($driver in $drivers)
    {
        Add-CMDriverToDriverPackage -Driver $driver -DriverPackageName $DriverPackageName

        #Output the driver class so that I can verify the result is HDC or NET.
        $driver.DriverClass
    }


}
    else
    {
        Write-Error -Message "Can't read Site: $site. Perhaps the SCCM CmdLets were not imported?"
    }

As you can see at one point in the script I output the driver class so that I can manually verify the output to the driver pack and all that is output is hdc or net driver classes.

driver class output


Solution

  • From what I can see there is nothing wrong with your script. I am working on a similar solution but I get the same result as you. The output list looks good but when adding the drivers to a package I get all sort of other drivers no matter what I do. The only thing common to the drivers I want to add (only hdc in my case) and the rest of the of the drivers added is the source path. If you bring up the "Content Source Path" column in the console you you can see that the hdc driver has the same source path as the other drivers added. So my conclusion is that Add-CMDriverToDriverPackage adds all driver in the same location regardless of the one specified in your search string.

    I think it's a flaw in the design of the cmdlet, it even says so in the description on Technet: https://technet.microsoft.com/en-us/library/jj850173(v=sc.20).aspx "When a device driver is added to a driver package, Microsoft System Center 2012 Configuration Manager copies the device driver content from the driver source location to the driver package."