locked
Moving PC to a different OU near the end of a Task Sequence RRS feed

  • Question

  • I've did a search through this forum for this, but the methods I've found haven't worked out for me. Does anyone here do this currently in their MDT? If so can you please share how you are pulling this off. I found a .vbs script that will work if I run it manually from a command prompt with the same credentials I have set to run as in the TS. But I cannot get it to run during the task sequence. Below is the vbs script and showing how I have had it listed in the TS. I have it set to run under a service account that has domain rights to move to OUs. 

    I have set it to run in the task sequence the following ways.

    cscript.exe "%SCRIPTROOT%\MoveOU.vbs" "OU=TEST OU,DC=MYDOMAIN,DC=COM"

    cscript.exe %SCRIPTROOT%\MoveOU.vbs "OU=TEST OU,DC=MYDOMAIN,DC=COM"

    \\mdtserver\deployshare$\scripts\MoveOU.vbs "OU=TEST OU,DC=MYDOMAIN,DC=COM"

    Here is the script.


    ' //***************************************************************************
    ' //***************************************************************************
    ' // ***** Script Header *****
    ' //
    ' // Solution:  ConfigMgr
    ' // File:      MoveComputerToCorrectOU.vbs
    ' // Author: Jakob Gottlieb Svendsen, Coretech A/S. http://blog.coretech.dk
    ' // Purpose:   Move computer to the correct OU that remains in variable MachineObjectOU
    ' // Run inside TS after install
    ' //
    ' // Usage:     MoveComputerToCorrectOU.vbs
    ' //
    ' //
    ' // CORETECH A/S History:
    ' // 0.0.1 JGS 17/12/2009  Created initial version.
    ' // 0.0.2 MIP 17/03/2009 Added feature to add argument to script
    ' // 0.0.3  JGS 02/12/2010  Changed to ADSystemInfo for the DN retrieval, instead of a homemade function.
    ' // Thanks to Nico_ at Technet Forums
    ' //
    ' // Customer History:
    ' //
    ' // ***** End Header *****
    ' //***************************************************************************
    '//----------------------------------------------------------------------------
    '//  Main routines
    '//----------------------------------------------------------------------------

    On Error Resume Next

    'Get MachineObjectOU Value
    Set wshNetwork = CreateObject("WScript.Network")
    Set oFso = CreateObject("Scripting.FileSystemObject")
    Set objSysInfo = CreateObject( "ADSystemInfo" )
    Set ArgObj = WScript.Arguments

    'Use first argument as target OU
    strMachineObjectOU = ArgObj(0)
    strComputerDN = objSysInfo.ComputerName

    nComma = InStr(strComputerDN,",")
    strCurrentOU = Mid(strComputerDN,nComma+1)
    strComputerName = Left(strComputerDN,nComma - 1)

    'If current ou is different than target OU. Move object
    If UCase(strCurrentOU) <> UCase(strMachineObjectOU) Then
    Set objNewOU = GetObject("LDAP://" & strMachineObjectOU)
    Set objMoveComputer = objNewOU.MoveHere("LDAP://" & strComputerDN, strComputerName)
    End If 

    '//----------------------------------------------------------------------------
    '//  End Script
    '//--------------------------------------------


    Thursday, July 20, 2017 3:38 PM

Answers

  • Found a solution that worked for me finally. Below is what I had to change to get it working with the script above. I didn't have to modify anything in the script. I also had to copy the script to the local computer, and run it from there. Please note the location for both my script and my batch file were located in my scripts folder under my deployment share of the MDT server.

    I changed the step in the TS to look like below. I also changed where I had the step located. I placed it under "Enable Bitlocker" (bitlocker is disabled in my TS though)

    

    My MoveOU.cmd contents

    copy \\mdtserver\deploymentshare\scripts\MoveOU.vbs c:\temp
    cscript.exe C:\temp\MoveOU.vbs "OU=Target OU,DC=yourdomain,DC=com"



    • Marked as answer by Jay9x Friday, July 21, 2017 1:21 PM
    Friday, July 21, 2017 1:20 PM

All replies

  • Found a solution that worked for me finally. Below is what I had to change to get it working with the script above. I didn't have to modify anything in the script. I also had to copy the script to the local computer, and run it from there. Please note the location for both my script and my batch file were located in my scripts folder under my deployment share of the MDT server.

    I changed the step in the TS to look like below. I also changed where I had the step located. I placed it under "Enable Bitlocker" (bitlocker is disabled in my TS though)

    

    My MoveOU.cmd contents

    copy \\mdtserver\deploymentshare\scripts\MoveOU.vbs c:\temp
    cscript.exe C:\temp\MoveOU.vbs "OU=Target OU,DC=yourdomain,DC=com"



    • Marked as answer by Jay9x Friday, July 21, 2017 1:21 PM
    Friday, July 21, 2017 1:20 PM
  • Here is the script which works fine for me, And the step need to be added where it will run as on a Full OS mode.

    ' //***************************************************************************
    ' // ***** Script Header *****
    ' //
    ' // Solution:  ConfigMgr
    ' // File:      MoveComputerToCorrectOU.vbs
    ' // Author: Jakob Gottlieb Svendsen, Coretech A/S. http://blog.coretech.dk 
    ' // Purpose:   Move computer to the correct OU that remains in variable MachineObjectOU
    ' // Run inside TS after install
    ' //
    ' // Usage:     MoveComputerToCorrectOU.vbs
    ' //
    ' //
    ' // CORETECH A/S History:
    ' // 0.0.1 JGS 17/12/2009  Created initial version.
    ' // 0.0.2 MIP 17/03/2009 Added feature to add argument to script
    ' // 0.0.3  JGS 02/12/2010  Changed to ADSystemInfo for the DN retrieval, instead of a homemade function.
    ' // Thanks to Nico_ at Technet Forums
    ' //
    ' // Customer History:
    ' //
    ' // ***** End Header *****
    ' //***************************************************************************
    '//----------------------------------------------------------------------------
    '//  Main routines
    '//----------------------------------------------------------------------------

    On Error Resume Next

    'Get MachineObjectOU Value
    Set wshNetwork = CreateObject("WScript.Network")
    Set oFso = CreateObject("Scripting.FileSystemObject")
    Set objSysInfo = CreateObject( "ADSystemInfo" )
    Set ArgObj = WScript.Arguments

    'Use first argument as target OU
    strMachineObjectOU = ArgObj(0)
    strComputerDN = objSysInfo.ComputerName


    nComma = InStr(strComputerDN,",")
    strCurrentOU = Mid(strComputerDN,nComma+1)
    strComputerName = Left(strComputerDN,nComma - 1)

    'If current ou is different than target OU. Move object
    If UCase(strCurrentOU) <> UCase(strMachineObjectOU) Then
    Set objNewOU = GetObject("LDAP://" & strMachineObjectOU)
    Set objMoveComputer = objNewOU.MoveHere("LDAP://" & strComputerDN, strComputerName)
    End If 

    '//----------------------------------------------------------------------------
    '//  End Script
    '//----------------------------------------------------------------------------


    • Proposed as answer by Anil.Prusty Wednesday, September 19, 2018 10:43 AM
    • Unproposed as answer by Anil.Prusty Wednesday, September 19, 2018 10:44 AM
    • Edited by Anil.Prusty Wednesday, September 19, 2018 10:45 AM
    Wednesday, September 19, 2018 10:43 AM