次の方法で共有


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 .

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Did you create the group first before running the script? Also you need to close the deployment work bench and open again after you have run the script. Unfortunately it does not dynamically update.

  • Anonymous
    January 01, 2003
    Hi Chris, Here is some code that will create a new driver group.   [System.Reflection.Assembly]::LoadFile("C:Program FilesBDD 2007BinMicrosoft.BDD.ConfigManager.dll") $manager = [Microsoft.BDD.ConfigManager.Manager] $drvGpMgr = $manager::DriverGroupManager $newItem = $drvGpMgr.CreateNew() $newItem["Name"] = "Test Group" $drvGpMgr.Add($newItem)   BEN

  • Anonymous
    January 01, 2003
    I hadn't tried that, but I have now! When I ran the command it returned the GUID for each driver. Can you suggest a better way to get that information and then produce a list that gives the name and group membership of the driver?   BEN

  • Anonymous
    January 01, 2003
    Hi Aaron, Can you send me a copy of your scripts so that I can test them? My email is ben dot hunter at microsoft dot com Thanks, Ben

  • Anonymous
    January 01, 2003
    Thanks for pointing out my error! My find and replace skills obviously need some work!! I have updated the entry. My script does assume that the Driver Group already exists. I will just have a look into creating a driver group itself using PowerShell and then come back to you. BEN

  • Anonymous
    January 01, 2003
    Ben, No luck still.  I've tried multiple driver group names and source folders. Everything runs without any errors (or with if I dont have the group or driver folder correct) but the drivers are not in the groups...even if I open/close the BDD workbench. Any further recommendations?  I've got about 40 base systems I have to manage the driver library for and the base BDD interface is basically unusable for group management after I have a few machines in place. Thanks! -Aaron

  • Anonymous
    January 01, 2003
    Ben, I'm running the script and it looks like its working as expected, drivers are added...output contains the correct group name, and it wont run without a valid group. However after it completes and all of the drivers show up they are not in the group I've specified. Any recommendations on what I should look at? Thanks, Aaron

  • Anonymous
    May 30, 2007
    Thanks for the great scripts!  This will save a lot of time. In the first script should these lines: $driverGroup.AddMember($driver["guid"]) $driverGroup.Update() be switched to: $dgadd.AddMember($driver["guid"]) $dgadd.Update() Does the first script assume the driver group already exists?  Is there a way to create a driver group outside of the gui (didn't see anything in the drivergroupmanager)?

  • Anonymous
    June 15, 2007
    Ben, sorry for the late reaction missed this post, did you ever try this ? ;-) $manager::DriverGroupManager | export-csv Greetings //o//

  • Anonymous
    September 07, 2007
    Ben, sorry for the late reaction missed your reaction, I found this comment again as I was searching for BDD 2007 driver import information, and your post was helpfull again ;-) I made a copy paste error I think , I missed the getDataTable()call e.g. : PoSH> [Microsoft.BDD.ConfigManager.Manager]::DriverGroupManager.GetDataTable() | Export-Csv dg.csv PoSH> gc dg.csv #TYPE System.Data.DataRow guid,enable,Name,drivergroup_Id {0bb9aa0f-a980-4c8f-bdf6-c3726d1005c7},,"All Drivers",0 as I'm really starting with BDD 2007 and PowerShell at work now for production usage as part of a big project, some more BDD and PowerShell content can expected on my blog. One thing I noticed allready is that adding BDD types was broken again in newer versions of PowerTab for 0.98 this is fixed and bdd completion is even faster as you can now do : [.bdd[tab] to get a list of all BDD types. Greetings //o//

  • Anonymous
    September 24, 2007
    Ben, I created the groups first and then imported the drivers.  I was refreshing the driver list and viewing the group membership. I will check tomorrow on closing the workbench after I run the import. Thanks! -Aaron

  • Anonymous
    December 11, 2007
    man this is a huge time saver.  Thanks Ben.  All I had to do was update the path to the assembly to get this to run with MDT.