Set AD Computer Description during OSD

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—————————-
19 Comments

Add a Comment

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.