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

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

Open in new window


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

Open in new window


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)

Open in new window

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

Open in new window


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/
prologic08Asked:
Who is Participating?
 
Nagendra Pratap SinghDesktop Applications SpecialistCommented:
I changed this to a loop and seems to be working OK for even 5 arguments.

==============================================
'-----Read commandline---
Set args = WScript.Arguments
For Each arg In args
strloc = strloc & " " & arg
next

Addcomploc strloc

Function addcomploc(strPCdescription)
 msgbox strloc
end function
=================================

Please check and let us know.
0
 
Nagendra Pratap SinghDesktop Applications SpecialistCommented:
Can't you use this

strloc = args(0) & ” ” & args(1) & ” ” & args(2) & ” ” & args(3)
0
 
prologic08Author Commented:
I just tried your suggestion. I tried adding a 3 word location like West Palm Beach. It did not enter anything into the Location field in AD. When I had just 1 argument, it added "West"

Any other suggestions?
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
Nagendra Pratap SinghDesktop Applications SpecialistCommented:
This worked partially. I got the string concatenation right. Screenshot
I don't have an AD with me but I would try adding quotes around objComputer.Put "Description",  " " & strPCdescription & " " and see.
0
 
prologic08Author Commented:
I think I got it..This is what I did..

dim Computerdn, strComputerName, 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

If args.count = 1 Then
	strdescription = args(0)
ElseIf args.count = 2 Then
	strdescription = args(0) & " " & args(1)
ElseIf args.count = 3 Then
	strdescription = args(0) & " " & args(1) & " " & args(2)
Else
	End If

Addcompdesc strdescription
Function addcompdesc(strPCdescription)
 Set objComputer = GetObject (strComputerDN)
 objComputer.Put "Description", strPCdescription
 objComputer.SetInfo
end function

Open in new window


I would prefer to use a Case statement but I don't know how... But this is working so unless we can redo that part as Case statements, I am ok with this. Thank you for your help as the 3 args helped me. If I don't hear back from you or anyone else in a few days, I will close this.
0
 
prologic08Author Commented:
Per-Fect!!!!!

Worked like a charm! Thank you so much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.