BDD 2007 – Tips and Tricks - Managing Driver Groups with PowerShell

BDD 2007 has a great technique of determining which drivers should be applied to the clients being deployed. It maintains a central driver library and then deploys the drivers based on the plug and play ID’s of the client.

So for example if we where deploying an HP DC7700 it would see that it has a Intel Pro 1000 network card and apply the appropriate driver to the client. This process works well until you realize that once we add the drivers to the driver library for the DC7700 we can affect the drivers that are applied to other hardware models.

This may not be a problem but a lot of sites must validate the drivers that are deployed to an image and they do not want unintended drivers to be deployed to their client devices.

To get around this issue BDD uses Driver Groups. Drivers can be added to a Driver Group and then you can specify the driver groups each model will receive. Through this process you can ensure that each hardware model will only receive the drivers that you specify.

This is good but unfortunately managing driver groups can be a time consuming and prone to errors. To add a driver to a group you need to open the drivers properties select the groups tab and then select the driver group that you wish to add this computer too. This process must be repeated for each driver you wish to add to the group.

The second issue that I have is determining what drivers are members of each group. You must look at each driver individually, a task that no one is keen to perform.

To get around these issues I have created a couple of PowerShell scripts, the first will import a set of drivers and add them to a specified group, and the second produces a CSV file listing each driver and the group it belongs to. These are relatively simple scripts but they should show the some of the ability's of PowerShell when managing BDD 2007. For further information on using PowerShell with BDD please refer to Michael Niehaus' blog.

IMPORTANT NOTE - When running PowerShell scripts please ensure that the BDD Workbench is closed .

Import Drivers and add to Driver Group

This script will import all the drivers in a specific folder and then add those drivers to a group. This script first imports all the drivers in the specified folder then it iterates through all the drivers in the driver library and adds any drivers that are a member of of only one group ("All Drivers") too the specified Driver Group. I have made the assumption that all drivers will be a member of the "All Drivers" group and one other group, using this assumption we are able to identify the newly added drivers and add them to the desired group.

Note - If the driver group name or source folder contains spaces then these should be enclosed in single quotes, for example:

          powershell .\Import-Drivers.ps1 'C:\Drivers\IBM T60' 'IBM T60'

# //***************************************************************************
# // ***** Script Header *****
# //
# // File: Import-Drivers.ps1
# //
# // Purpose: Imports Drivers and assigns them to a group
# //
# // Usage: powershell .\Import-Drivers.ps1 [Drivers Location] [Driver Group]
# // Drivers Location – The folder containing the drivers to be imported
# // Driver Group - BDD Driver group name. Driver group to which the drivers will be added. - This is case sensitive.
# //
# // Notes:
# //***************************************************************************
Param
(
    [string]$DriverLocation,
    [String]$Group
)

[System.Reflection.Assembly]::LoadFile("C:\program files\BDD 2007\bin\Microsoft.BDD.ConfigManager.dll")
$manager = [Microsoft.BDD.ConfigManager.Manager]
write-host "Driver Location: " $DriverLocation
write-host "Driver Group: " $Group
$dgmgr = $manager::DriverGroupManager
$dmgr = $manager::DriverManager

# Refresh the Driver Groups to ensure we can see any new groups
$dgmgr.Refresh()

# See if the group exists
$dgadd = $dgmgr.Find($Group)
if ($dgadd -eq $null)
{
    write-host "Driver Group does not exist, please specify "
}
else
{
    $dmgr.Import($DriverLocation)
    $dmgr.Refresh()
    foreach ($driver in $dmgr)
    {
        # Count the number of gr0ups that this driver is a member of
        $intcount = 0
        foreach ($DriverGroup in $dgmgr)
       {
            # Make sure the driver is in the group
           if ($driverGroup.IsMember($driver["guid"]))
            {
                $intcount++
            }
       }
       if ($intcount -eq 1)
       {
            # Make sure the driver is in the group
            if (-not $dgadd.IsMember($driver["guid"]))
            {
                write-host "Adding driver " $driver["name"] " to group " $Group
                $dgadd.AddMember($driver["guid"])
                $dgadd.Update()
            }
        }
    }
}

Reporting on Driver Groups

This script simply lists each group and the drivers that are a member of the group in a CSV format. It is very simple but does the job!

# //***************************************************************************
# // ***** Script Header *****
# //
# // File: DGMembershipReport-csv.ps1
# //
# // Purpose: Creates an CSV report on driver group membership
# //
# // Usage: powershell .\DGMembershipReport-csv.ps1
# //
# // Notes:
# //***************************************************************************

[System.Reflection.Assembly]::LoadFile("C:\program files\BDD 2007\bin\Microsoft.BDD.ConfigManager.dll")
$manager = [Microsoft.BDD.ConfigManager.Manager]
$CSVFilePath = ".\DriverGroups.CSV"
$strDate = get-date -uformat "%Y/%m/%d"
$strOutputString | out-file -filepath $CSVFilePath -encoding ascii

# Create and write CSV to file
$strOutputString = "Driver Group Membership Report"
$strOutputString | out-file -filepath $CSVFilePath -encoding ascii -append
$strOutputString = "Date: " + $strdate
$strOutputString | out-file -filepath $CSVFilePath -encoding ascii -append

foreach ($DriverGroup in $manager::DriverGroupManager)
{
    foreach ($driver in $manager::DriverManager)
    {
        if ($driverGroup.IsMember($driver["guid"]))
        {
           $strOutputString = $driverGroup["Name"] + "," + $driver["Name"]
           $strOutputString | out-file -filepath $CSVFilePath -encoding ascii -append
        }
    }
}

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .