Menu
CCMEXEC.COM – Enterprise Mobility
  • Home
  • General
  • Configuration Manager
  • Windows 10
  • Intune
  • GitHub
  • Windows 11
  • About the author
CCMEXEC.COM – Enterprise Mobility

Set AD Computer Description during OSD

Posted on January 26, 2012January 26, 2012 by Jörgen Nilsson

There was a question on Technet forum a couple of weeks ago so I thought I would post it here as well. It can in some scenarios be useful to set the computers AD description during SCCM OS deployment. I use a script for this which can be used to set the AD description using  a variable like for instance a Computer or Collection variable that can be filled in during the deployment or a value from MDT variables if you like.

This is the script I use:


dim Computerdn, strComputerName

dim Args

Set WshShell = WScript.CreateObject("WScript.Shell")

'----Get Computer DN------

Set objADSysInfo = CreateObject("ADSystemInfo")

ComputerDN = objADSysInfo.ComputerName

strcomputerdn = "LDAP://" & computerDN

Set objADSysInfo = Nothing

'-----Read commandline---

Set args = WScript.Arguments

strdesc = args(0)

Addcompdesc strdesc

Function addcompdesc(strPCdescription)

Set objComputer = GetObject (strComputerDN)

objComputer.Put "Description", strPCdescription

objComputer.SetInfo

end function

Then I run it from a package in the task sequence. It must be run after the “Setup Windows & ConfigMgr” step, so that the computer is restarted after it is joined to the domain.
The account which executes the script must have permissions in the AD to set the AD Description. Just replace the %desc% with the variable you want to use or static value if you want to use that.

ADDesc1

If you want to be prompted for an AD description when the Task Sequence starts create a Collection variable for the OSD Collection with an empty value like this:

ADDesc2

dim Strdomainpath
dim Computerdn, strComputerName
dim Args
Set WshShell = WScript.CreateObject(“WScript.Shell”)
‘—-Get Computer DN——
Set objADSysInfo = CreateObject(“ADSystemInfo”)
ComputerDN = objADSysInfo.ComputerName
strcomputerdn = “LDAP://” & computerDN
Set objADSysInfo = Nothing
‘—–Read commandline—
Set args = WScript.Arguments
strdesc = args(0)
Addcompdesc strdesc
Function addcompdesc(strPCdescription)
Set objComputer = GetObject (strComputerDN)
objComputer.Put “Description”, strPCdescription
objComputer.SetInfo
end function—————————-

27 thoughts on “Set AD Computer Description during OSD”

  1. Stefan says:
    August 17, 2012 at 12:26 pm

    Works perfectly. Thankyou!

    Reply
  2. Pingback: Dynamically join Computer to AD OU during OSD with SCCM | The D-Spot
  3. sweetsandy says:
    April 18, 2013 at 1:42 pm

    hi Jorgen, i want to be prompted an AD description when the Task Sequence starts. i had created veriable “OSDComputerDesc” in the past but it did not work. could you please tell if i create collection variable “Desc”, i still need to create the script for which you are using to set a task sequence veriable? if yes, could you please tell how can i create this script? can i just copy this content and paste in a specific file format? i am not good in scripting stuff.

    Reply
    1. Jörgen Nilsson says:
      April 25, 2013 at 8:55 am

      Hi,
      You can use the script exactly as it is, copy the content and save it as .vbs then you should be good to go.
      /Jörgen

      Reply
      1. Jason P says:
        May 25, 2022 at 9:00 pm

        I have a similar use case. I’ve modified the DeployWiz_ComputerName.xml to capture a “OSDComputerDescription” object:

        I then try calling your VBS script after the OS Install step like this:

        cscript.exe “%SCRIPTROOT%\adcompdesc.vbs %OSDComputerDescription%”

        …but it does not set the AD property. Any suggestions?

        Reply
  4. Cody Makiva says:
    May 13, 2013 at 8:19 pm

    Hi, I am currently running CM 2012 without MDT integrated. I tried running your script in the same spot in the task sequence as you showed above but it receives the following error:

    Line: 11
    Character: 1
    Error: Active X component can’t create object: ‘ADSystemInfo’
    Code: 800A01AD
    Source: Microsoft VBScript runtime error

    Is there any additional functionality that I need to add to WinPE for this script to work? The WinPE-Scripting package is installed by default on this version of PE but I’m not sure if that’s all it needs. Any ideas would be greatly appreciated. Thanks,

    Cody

    Reply
  5. Jim says:
    August 19, 2014 at 9:46 pm

    Thanks for the post Jörgen. I am have some trouble with the implementation through SCCM. As far as the package goes, is it essentially a package with 0 program, and only source files pointing to the directory containing the VBS? The script works fine if i launch from the command line in windows, nothing seems to happen during OSD. Any help is appreciated. Thanks!

    Reply
  6. Daniel says:
    February 23, 2015 at 5:59 am

    Hello Jörgen,

    I have tried your method for defining description while OSD Task Sequence. But i have some query regarding this.

    1. Task sequence doesn’t prompt for description like any “Input Box”

    2. Second, variable which we define at collection it takes value from that and apply it to AD Description, but its does not accept any letter after “space”

    What i want??

    I want a prompt for description while OSD setup which should be mandotary part of installation and that description added into AD Computer Account.

    Reply
  7. Jörgen Nilsson says:
    April 20, 2015 at 9:58 pm

    Hi, Daniel the script doesn’t prompt you for any input you can do that using an collection variable with an empty value. then you will be prompted. It can handle space if you put what you want to write within ” “.

    Reply
  8. Jörgen Nilsson says:
    April 20, 2015 at 10:00 pm

    To be able to write two variables to the description field, replace the following line:
    strdesc = args(0)

    with
    strdesc = args(0) & ” ” & args(1) note that it will fail if there are only one variable passed to it..

    /jörgen

    Reply
  9. Sunny says:
    May 26, 2015 at 10:59 pm

    Hey Jörgen this is a great post and it has happed me out a lot but I was wondering is there anyway to use your script and tie it into a UDI install what I want to do is add a custom page to add the Computer description instead of being prompted something like the below link but using your script

    http://blogs.technet.com/b/jchalfant/archive/2014/08/13/set-local-computer-description-during-configuration-manager-task-sequence.aspx

    Reply
    1. Jörgen Nilsson says:
      May 26, 2015 at 11:05 pm

      Hi,
      Yes it will work the same way, use the same instructions that Justin has written and use the OSDCOmputerDEscription variable with the script from my blog, it will work just fine.
      /Jörgen

      Reply
  10. Jeff says:
    June 10, 2015 at 6:44 pm

    Great work – thanks for this walkthrough.

    I noticed that entering descriptions with spaces will only capture the first word before the space. Adding quotes around the variable resolved in the task sequence resolved this for me: cscript.exe adcomdesc.vbs “%desc%”

    Reply
  11. Richard Green says:
    January 29, 2016 at 11:14 pm

    Hello,

    I know this post has been around awhile, but I have a question. In you post above I see that you have added a domain account in the “Run this step as the following account” field. I would like to know if anyone know of a way to utilize the OSDJoinaccount & OSDJoinPassword Collected during the UDI interface.

    I have tried a few thing including a VBRunAs script, Powershel PScredentials, and PSexec with a -u and -p option. All of these option work fine in a full windows environment, but I always run into a permissions denied error if the script is run during the OSD TS.

    Anyone have any ideas

    Reply
  12. Mike Murray says:
    May 5, 2016 at 1:36 am

    Hello,

    I tried using your method to update the computer location in AD instead of description. I want to include two OSD variables – %OSDBuildingCode% and %OSDRoomCode% with a space in between. I switched the args section like you said:

    strdesc = args(0) & ” ” & args(1)

    My command line in the TS is CSCRIPT.EXE Location.vbs %OSDBuildingCode% %OSDRoomCode%

    The SMSTS.log shows it passing it as ‘CSCRIPT.EXE Location.vbs BLDG ROOM’

    But it errors out with “C:\_SMSTaskSequence\Packages\CMC002E5\Location.vbs(14, 21) Microsoft VBScript compilation error: Invalid character”

    Here is my script:

    dim Computerdn, strComputerName
    dim Args

    Set WshShell = WScript.CreateObject(“WScript.Shell”)
    ‘—-Get Computer DN——
    Set objADSysInfo = CreateObject(“ADSystemInfo”)
    ComputerDN = objADSysInfo.ComputerName
    strcomputerdn = “LDAP://” & computerDN
    Set objADSysInfo = Nothing

    ‘—–Read commandline—
    Set args = WScript.Arguments
    ‘strdesc = args(0)
    strdesc = args(0) & ” ” & args(1)
    Addcompdesc strdesc

    Function addcompdesc(strLocation)

    Set objComputer = GetObject (strComputerDN)

    objComputer.Put “Location”, strLocation
    objComputer.SetInfo

    end function

    Any help is appreciated!

    Reply
    1. Jörgen Nilsson says:
      May 5, 2016 at 8:25 am

      Hi,
      I just tested this and it works just fine. Hope it helps.
      /Jörgen

      dim Computerdn, strComputerName
      dim Args

      Set WshShell = WScript.CreateObject(“WScript.Shell”)
      ‘—-Get Computer DN——
      Set objADSysInfo = CreateObject(“ADSystemInfo”)
      ComputerDN = objADSysInfo.ComputerName
      strcomputerdn = “LDAP://” & computerDN
      Set objADSysInfo = Nothing

      ‘—–Read commandline—
      Set args = WScript.Arguments
      ‘strdesc = args(0)
      strdesc = args(0) & ” ” & args(1)
      wscript.echo strdesc
      Addcompdesc strdesc

      Function addcompdesc(strLocation)

      Set objComputer = GetObject (strComputerDN)
      objComputer.Put “Location”, strLocation
      objComputer.SetInfo

      end function

      Reply
  13. Mike Murray says:
    May 5, 2016 at 11:00 pm

    It’s working now. Thanks!

    Reply
  14. Patricia Babson says:
    June 13, 2016 at 6:15 pm

    Hi, I really need some help with this. Here is what I have:

    dim Computerdn, strComputerName, strdesc, strfdesc

    Set WshShell = WScript.CreateObject(“WScript.Shell”)

    ‘—-Get Computer DN——

    Set objADSysInfo = CreateObject(“ADSystemInfo”)

    ComputerDN = objADSysInfo.ComputerName

    strcomputerdn = “LDAP://” & computerDN

    Set objADSysInfo = Nothing

    ‘—–Read commandline—

    Set args = WScript.Arguments

    strdesc = args(0)

    strfdesc = “SCCM: ” & strdesc & ” Imaged: ” & Date

    Addcompdesc strfdesc

    Function addcompdesc(strPCdescription)

    Set objComputer = GetObject (strComputerDN)

    objComputer.Put “Description”, strPCdescription

    objComputer.SetInfo

    end function

    I’m using:

    cscript.exe adcompdesc.vbs “%ADDesc%”

    To pass the variable into it and I can see where it’s getting passed in but the script completes and the AD Description is still not set.

    Thanks!
    Patricia

    Reply
  15. Miguel says:
    June 30, 2016 at 12:52 am

    Hello Jörgen,

    I’m using MDT 2012… Could this script work with MDT too? Would I need to make any changes to make it work? If so how could I get the script to prompt me for a description and update both the computer and AD computer description?

    Thanks in advance!

    Reply
  16. Kaspars says:
    November 12, 2018 at 11:43 am

    Hi. Do you have any clue why do I get error? Account has all rights in AD. My TS step is cscript.exe %scriptroot%\addesc.vbs “%tsvariable%” it is after Use toolkit package step.
    The task sequence execution engine failed executing the action (Computer Description in AD) in the group (State Restore) with the error code 1
    Action output: [ smsswd.exe ]
    PackageID = ”
    BaseVar = ”, ContinueOnError=”
    ProgramName = ‘cscript.exe C:\_SMSTaskSequence\WDPackage\Scripts\addesc.vbs “Name Surname”‘
    SwdAction = ‘0001’
    Getting linked token
    failed to get the linked token information. It may notbe available. Error 1312
    Get RunAs private desktop SMSTS-17906\SMSTSDesktop
    Run command line under a user account
    Command line for extension .exe is “%1” %*
    Set command line: Run command line
    Working dir ‘not set’
    Executing command line: Run command line
    Create a process under given user token
    Microsoft (R) Windows Script Host Version 5.812
    Copyright (C) Microsoft Corporation. All rights reserved.

    P. The operating system reported error 1: Incorrect function.

    Reply
  17. Henrik says:
    February 20, 2019 at 12:09 pm

    Hi Jörgen!
    Great script!
    Is there an easy way to modify the script to remove/clear the description?
    /Henrik

    Reply
  18. John says:
    March 11, 2019 at 4:38 pm

    Would this still work for Windows 10 1809

    Reply
    1. Jörgen Nilsson says:
      March 14, 2019 at 7:26 am

      Yes, it works great!
      Regards,
      Jörgen

      Reply
  19. Austin says:
    November 26, 2019 at 2:40 am

    is there any way to put this into the MDT UI without SCCM?

    Reply
  20. Tariq says:
    February 22, 2023 at 4:26 pm

    Hi,

    When I run the .vbs script, I get the error:
    Line:4
    Char: 37
    Error: Invalid Character
    Code: 800A0408

    Please help!

    Thanks

    Reply
    1. Jörgen Nilsson says:
      February 25, 2023 at 3:00 pm

      Hi,
      I would recommend using the PowerShell version of the script instead. https://ccmexec.com/2018/03/powershell-osd-scripts-to-addremove-computer-from-ad-group-and-set-ad-description/
      Regards,
      Jörgen

      Reply
      1. Tariq says:
        February 28, 2023 at 3:04 am

        Hi Jörgen,
        Thanks for your reply. How can set a customized description for each time I am imaging a computer? I need to take the input for the description and update in AD.

        Can you please help?

        Thanks

        Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

My name is Jörgen Nilsson and I work as a Senior Consultant at Onevinn in Malmö, Sweden. This is my blog where I will share tips and stuff for my own and everyone elses use on Enterprise Mobility and Windows related topics.
All code is provided "AS-IS" with no warranties.

Tweets by ccmexec

Recent Posts

  • Windows Servicing, Personal Teams and Success.cmd
  • Windows MDM Security Baseline – Settings Catalog
  • Configuring MS Edge Security Baseline v107 using Settings Catalog
  • Configuring Desktop App Installer using CSP and script?!
  • Customizing Taskbar and Start in Windows 11 22h2 with PowerShell

©2023 CCMEXEC.COM – Enterprise Mobility | WordPress Theme by Superb Themes
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT