none
Join specfic AD depending on the computer name RRS feed

  • Question

  • Hi,

    I'm looking for some help please with this problem, if someone have any advices/directions:

    - I want to join the machine deployed with MDT 2012 update 1 (Win 7 64bit) to a specific AD OU, depending on the machine name. I'm able to do this for the task sequences where the machines goes always to the same container (by manipulating the TS variable MachineObjectOU), but the problems come when there are more the one OU where the machines may end up (now we move them manualy at the end of the imaging process). 

    - I tried to ran some queries on the steps that assigns the value for the MachineObjextOU using an if condition ("Select * from Microsoft.SMS.TSEnvironment WHERE OSDComputerName like "ABC%" " or this one "Select * from Microsoft.SMS.TSEnvironment WHERE _SMSTSMachineName like "ABC%" " ) but without success.

    - Also I tried to see if I can find any ways to assign the first three characters from the computer name to an user defined TS variable, and compare that variable using again the If condition (equals) but without success (the bigest problem was I couldn't find something to allow me to assign/compare only the first three characters of the computer name from the OSDComputerName/_SMSTSMachineNamen variables)

    - Initially I tested some scripts that were trying to move the machines at the end of the TS, but they failed (the main problem was the user under I ran them (for some reasons they were running under the local admin account), even I tried to use the option "Run this optin as the following account", because when I ran them manually, logging in under the intended account (an AD account with privileges to move machines in AD OU), they worked).

    So, this is my situation. If possible, I'll like to find a way to manipulate those TS variables inside the TS (because then I'll be able to use this for other needs, too), but also a script is good. Thank you for any help that you can provide!



    • Edited by Doru1234 Monday, July 11, 2016 7:45 PM
    Monday, July 11, 2016 7:42 PM

All replies

  • Create a Task Sequence Variable for each OU with the following Task Sequence Variable: MachineObjectOU

    Value: distinguished name of the OU

    Condition: select * from win32_computersystem where name like "%computername%"

    The % signs are wildcards, so you may choose COMP% and LAP%, so everything after the % isn't relevant for matching the WMI Query.

    Cheers! Rens


    If this post is helpful please click "Mark for answer", thanks! Kind regards

    Wednesday, July 13, 2016 12:10 PM
  • Thanks, Rens! I tried your suggestion but it didn't work (I used a query like this: select * from win32_computersystem where Name like "ABC%" and name the machine ABC-Test). I tried to set and test that variable before and after the installation of the OS (I created a step for this at the beginning of the TS, after the "Installing OS" step and in the State Restore section, before "Recover from domain") but with the same result. The query is working, if I set it as a condition for a diffrent step (I tested with "Restart Computer").

    I think this approach won't work to set the AD OU for the machines that are imaged because that query might not work before the installation of the OS, because that object/entity (win32_computersystem) is specific to the target machine, and if I try to run the query before the insalllation of the OS, I won't have on what to run it. If I ran the query after the installation, I think it's already too late (it's possible to be wrong, but I think the machine are joined to the domain during the installation of the OS and after that the Recovery from the domain step is designed to work only if the previous step wasn't succesful). Because of this problems I tried to run a WMI query on an object/entity specific to the TS/deployment system (Microsoft.SMS.TSEnvironment), and not to the target machine, that stores the computer name filled in at the beginning of the imaging process, but I couldn't find the right one :(.


    • Edited by Doru1234 Wednesday, July 13, 2016 7:18 PM
    Wednesday, July 13, 2016 6:08 PM
  • You are right, the variables get defined before the OS install.  BUT is you rerun the gather later in your task sequence, the Rens' suggestion should work.
    Wednesday, July 13, 2016 9:21 PM
  • I'm sorry BiAtE-Z but I'm not sure I get your idea: what do you mean by "rerun the gather later"?
    Thursday, July 14, 2016 12:59 AM
  • Copy a gather task from earlier in the task sequence and place it after the task where the Task Sequence Variable is defined. 
    Thursday, July 14, 2016 3:46 PM
  • I tried it but it doesn't work. I think the reasons that I presented earlier are the cause of this (before the insallation of the OS there isn't a "win32_computersystem" entity on the target machine, and after the OS is installed, is too late, because the machine is already joined to the domain and placed in the "Computers" container).
    Friday, July 15, 2016 2:24 PM