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.
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:
Works perfectly. Thankyou!
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.
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
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?
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
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!
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.
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 ” “.
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
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
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
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%”
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
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!
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
It’s working now. Thanks!
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
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!
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.
Hi Jörgen!
Great script!
Is there an easy way to modify the script to remove/clear the description?
/Henrik
Would this still work for Windows 10 1809
Yes, it works great!
Regards,
Jörgen
is there any way to put this into the MDT UI without SCCM?
Hi,
When I run the .vbs script, I get the error:
Line:4
Char: 37
Error: Invalid Character
Code: 800A0408
Please help!
Thanks
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
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