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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prologic08Author Commented:
Per-Fect!!!!!

Worked like a charm! Thank you so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server Apps

From novice to tech pro — start learning today.