Querying the MDT database using a custom model

This seems to be a frequent question that comes up:

“I am working with PCs from <vendor> that have model strings that frequently change, although the first part is always consistent.  How can I use these models with the MDT database without creating a new entry for each unique string?”

This seems to come up most often with computers from Lenovo, where the first four characters indicate the model and the last three indicate a specific configuration of that model.  It’s also seen with various HP computers, although their pattern tends to be a little more difficult.

The “gather” process that MDT uses doesn’t provide a way to do wildcard or “like” queries, but it does provide extensibility to let you define your own property to use instead of “Model” when querying the database.  Let me give a “real world” example for the Lenovo case.  I can use a CustomSettings.ini like this:

Priority=CalculateCustom, MMSettings

CustomModel=#Left("%Model%", 4)#

Parameters=Make, CustomModel

This defines a new property called “CustomModel”.  It includes a rule that has a very simple manipulation: it sets the value to the first four characters of the existing “Model” value, which in the case of my T61p laptop results in a value of “6458”.

I then modified the database query to tell it to use “CustomModel” as a parameter instead of “Model”.  If that’s all I did, the query would fail because it would create a SQL statement that specified “WHERE CustomModel = ‘6458’” but that’s not valid since there isn’t a CustomModel column in the database.  That’s where the next line comes in:


This says that the property “CustomModel” as we know it locally is called “Model” in the database.  As a result, the correct query is generated:

About to issue SQL statement: SELECT * FROM MakeModelSettings WHERE MAKE = ‘LENOVO’ AND Model = ‘6458’
Successfully queried the database.

That’s all it takes.  Now, there would typically be more than just the [MMSettings] section that needs the “CustomModel” updates – you would also want to change [MMPackages], [MMApps], [MMAdmins], and [MMRoles] the same way.

If you need to do a calculation that is more complex than the simple substring that I implemented above, you may need to use a user exit to do the calculation.  The end of the exit just needs to set the same “CustomModel” property.  The rest of the logic would be the same.  So you could use something like this for the exit:

Function UserExit(sType, sWhen, sDetail, bSkip)

    If sType = "SECTION" and sWhen = "BEFORE" then

        oLogging.CreateEntry "Calculating custom model string.", LogTypeInfo

        If UCase(oEnvironment.Item("Make")) = "LENOVO" then
            oEnvironment.Item("CustomModel") = Left(oEnvironment.Item("Model"), 4)
        ElseIf Instr(oEnvironment.Item("Model"), "(") > 2 then
            oEnvironment.Item("CustomModel") = Trim(Left(oEnvironment.Item("Model"), Instr(oEnvironment.Item("Model"), "(") – 2))
            oEnvironment.Item("CustomModel") = oEnvironment.Item("Model")
        End if

    End if

    UserExit = Success

End Function

Save that as “CustomModelExit.vbs” in the same “Scripts” directory with ZTIGather.wsf, then edit the CustomSettings.ini to specify to run it:

Priority=CalculateCustom, MMSettings


Parameters=Make, CustomModel

The only change from the previous CustomSettings.ini sample is the [CalculateCustom] section.  Now it specifies the run the user exit script.  So what exactly does this script do?  Well, if it’s a Lenovo machine, it takes the first four characters.  If the models string contains a starting parenthesis, “(“, it will chop everything from that point off of the model (e.g. “My Model (Test)” will become “My Model”).  In any other case, the script will assign the current model value to the CustomModel property.  (That simplifies things somewhat.)

You might need to tweak the script some based on your specific requirements, but the basic setup should work for whatever manipulation you would like to do.

Comments (10)
  1. I agree that web services are a great way to do more complex manipulations, running the code on the back end instead of on the client and then just returning a set of variable values for the client to use.

    You just need to be a developer (or a developer at heart) to create and implement these.


  2. Anonymous says:

    It is also very useful to do this same type of lookup using webservices. This way you can pass the model name (such as HP’s with the random digits at the end) to the webservice, and then using .NET code parse the model name before returning a result back to your build.

    This gives you the added benefit of it being central also – if all your build servers hit this webservice, you won’t need to update customsettings on each one of your Deployment Pointss every time you add a new model, simply make sure your webservice returns the proper value, and you’re all set.

  3. Anonymous says:


    you can download


    which michael wrote, for just this purpose 🙂


  4. Because we’re using a SQL query from the client side, we can’t do wildcard matching without reading all of the rows and comparing them.  (It’s backwards from the normal SQL "LIKE" processing.) That’s doable, but potentially not very efficient – it would be better done on the server side through a stored procedure.

    It’s something that was considered for MDT 2010, but we didn’t have time to get it done.


  5. Yes, you could build a folder structure something like "Out-of-box DriversLenovo6483" and then specify in CustomSettings.ini "DriverGroup001=%Make%%Model%".  More on that in a future post…


  6. Anonymous says:

    Is it possible during the inital config screen to add a window that will have drop down boxes to select item’s that will be written as variables for the deployment?  

    Basically what I am looking to do is to use the wizardeditor to add a new pane that will have a series of drop down boxes to select things like Grade and Floor that the pc is on so that I can use that to determine what OU to put the client workstation in?  

    I would also like to make two drop down’s for computer name so they can select room number and pc location and those two varibles will be merged to equal the computer name.

  7. Anonymous says:


    Is there any way to do something similar in MDT 2010. In your script you adjust %model% to the new determined %CustomModel% based on your script.  Now that we have folders in MDT 2010 What I would like to do is use the newly determined %model% in the TS for injecting the drivers from a specific driver folder in MDT.  Somehow use the injectdrivers task to use the %model% folder for injecting the drivers

    maybe its a bad idea 😉



  8. Anonymous says:

    Hi Michael,

    This works well for us with some HP models, but it’d be really good if we could just use the database and put in "HPDC7600%" as the model name and have the scripts accept the wildcard. I’m sure there’s a very good reason why we can’t…


  9. Tim Nielsen says:

    Hi Mike, I just wanted to say thank you for all the posts you have created on MDT. Over the years they’ve been extremely helpful to me.

  10. showbox says:

    Thanks for the great info. I really loved this. I would like to apprentice at the same time as you amend your web site, how could i subscribe for a blog site?
    For more info on showbox please refer below sites:
    Latest version of Showbox App download for all android smart phones and tablets.
    http://movieboxappdownloads.com/ – It’s just 2 MB file you can easily get it on your android device without much trouble. Showbox app was well designed application for android to watch movies and TV shows, Cartoons and many more such things on your smartphone.
    For showbox on iOS (iPhone/iPad), please read below articles:
    Showbox for PC articles:
    There are countless for PC clients as it is essentially easy to understand, simple to introduce, gives continuous administration, effectively reasonable. it is accessible at completely free of expense i.e., there will be no establishment charges and after establishment
    it doesn’t charge cash for watching films and recordings. Not simply watching, it likewise offers alternative to download recordings and motion pictures. The accompanying are the strides that are to be taken after to introduce Showbox application on Android.
    The above all else thing to be done is, go to the Security Settings on your Android telephone, Scroll down and tap on ‘Obscure sources’.

Comments are closed.