Schuff at myITforum.com

Blog it to log it!

BDD & Powershell

Rod set me up with my blog spot on myITforum so I can finally start rambling to whoever doesn't want to listen. ;)  I am guessing most of my blogs are going to be focused around BDD, VBScripts, Powershell, & SMS.

So I noticed Michael Niehaus's blog from Saturday talking about using BDD & Powershell together.  He posted a great example on using Powershell to query the drivers in BDD and create groups based on each drivers manufacterer and add the drivers to the groups.  I thought this was a perfect example to get minds thinking of the possibilities of scripting or automating BDD workbench.

 So I started playing around with a few of the commands just for testing. It really helps having the BDD Source code on hand to look into the source for available functions and such. The one I initially wanted to play with was the databaseconnection object. This allowed me to do direct queries to the database utilizing the Microsoft.BDD.ConfigManager.dll.   Here is a poor example of a powershell query that returns roles assigned to specific data set at the top of the script. You can see how this could create a nice report.

 # Initialization

$MycompAssetTag = "4330-9718-9298-1100-7864-6575-19"
$MyGateway = "10.20.30.1"
$MyMake = "IBM"
$MyModel = "T43"

[System.Reflection.Assembly]::LoadFile("C:\Program Files\BDD 2007\bin\Microsoft.BDD.ConfigManager.dll")
$manager = [Microsoft.BDD.ConfigManager.Manager]

write-host ""
write-host "The following roles apply to your computer:"


# Get ComputerSettings (Need computer AssetTag, UUID, SerialNumber, MacAddress)

foreach ($computerItem in $manager::databaseConnection.Table("ComputerIdentity"))
{
  If ($computerItem["AssetTag"] -eq $MycompAssetTag)
  {
    $compID = $computerItem["ID"]
  }
}

# Get Locations (Need computer AssetTag, UUID, SerialNumber, MacAddress)

 

foreach ($defaultGateway in $manager::databaseConnection.Table("LocationIdentity_DefaultGateway"))
{
  If ($defaultGateway["DefaultGateway"] -eq $MyGateway)
  {
    $GatewayID = $defaultGateway["ID"]
  }
}


# Get Locations (Need computer AssetTag, UUID, SerialNumber, MacAddress)

 

foreach ($MakeModel in $manager::databaseConnection.Table("MakeModelIdentity"))
{
  If ($MakeModel["Make"] -eq $MyMake)
  {
    If ($MakeModel["Model"] -eq $MyModel)
    {
      $MakeModelID = $MakeModel["ID"]
    }
  }
}

# Get Computer Roles

foreach ($computerRole in $manager::databaseConnection.Table("ComputerRoles"))
{
  If ($computerRole["ID"] -eq $CompID)
  {
    write-host - $computerRole["Role"]   
  }
}

# Get Location Roles

foreach ($LocationRole in $manager::databaseConnection.Table("LocationRoles"))
{
  If ($LocationRole["ID"] -eq $GatewayID)
  {
    write-host - $LocationRole["Role"]
  }
}


# Get Make/Model Roles

foreach ($MakeModelRole in $manager::databaseConnection.Table("MakeModelRoles"))
{
  If ($MakeModelRole["ID"] -eq $MakeModelID)
  {
    write-host = - $MakeModelRole["Role"]
  }
}

 

 

Comments

dhite said:

Welcome to the Blog! Have fun and ramble on until you can’t ramble on no more…or at least until Kristy tells you to go outside and play with Austin and Ashleigh. - Don

# April 24, 2007 2:31 PM

jscheffelmaer said:

Thanks Don! I suppose its healthier for me to see the sun now and then eh. :)

# April 25, 2007 9:27 AM