prologic08
asked on
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/):
The one above will populate the Description field in AD.
The one below is identical only it will populate the Location field in AD.
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:
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/
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)
TOstrloc = 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
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?
Any other suggestions?
ASKER
I think I got it..This is what I did..
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.
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Per-Fect!!!!!
Worked like a charm! Thank you so much.
Worked like a charm! Thank you so much.
strloc = args(0) & ” ” & args(1) & ” ” & args(2) & ” ” & args(3)