troubleshooting Question

SCCM PXE populating fields in AD through VBS and the Task sequence

Avatar of prologic08
prologic08 asked on
Microsoft ApplicationsMicrosoft Server AppsIT Administration
6 Comments1 Solution620 ViewsLast Modified:
I am looking to populate AD fields like the Location and Description field via a VB Script. This will happen during the PXE Task Sequence in SCCM. I found a script that does exactly what I want and it works almost exactly how I wanted it. Here is the code for the Descrption field (Credit: http://ccmexec.com/2012/01/set-computer-description-during-osd/):

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

The one above will populate the Description field in AD.
The one below is identical only it will populate the Location field in AD.

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
strloc = args(0)
Addcomploc strloc
Function addcomploc(strPCdescription)
 Set objComputer = GetObject (strComputerDN)
 objComputer.Put "Location", strPCdescription
 objComputer.SetInfo
end function

If you take a look at the link that I gave credit to, it gives a step by step to implement this. I was able to successfully implement it and it works ALMOST to my specifications. What it does not do is allow you to enter more than 1 word for each value. So if I wanted to put Miami in the input field when SCCM starts the TS, it will work fine but if I put New York, it will only add the word New to the location field in AD. I read the comments in the link above and it says that in order to input two variables, you change:

strloc = args(0)
TO
strloc = args(0) & ” ” & args(1)

The problem with this is if you had one word or three words or more, it fails. I have also tried putting two words in quotes and that doesn't work either.

I have two questions bout this. Can someone come up with a way to make this work so that I can put anywhere from 1 to 4 word in the description field?

And also if possible, Is there a way to change the whole script around to allow us to just input the username of the user and have it populate the location and the OU. We always create the user account first and it contains the location and based on some info within the AD user account, we can figure out which OU the machine will be added to.

The way I have it going to a specific OU currently is by using the following:
http://www.the-d-spot.org/wordpress/2013/04/01/dynamically-join-computer-to-ad-ou-during-osd-with-sccm/
ASKER CERTIFIED SOLUTION
Nagendra Pratap Singh
Desktop Applications Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros