/build/static/layout/Breadcrumb_cap_w.png

Automated PC name based on current names in AD vbscript.

Hello,

I've been a lurker on here for a while now and have gained much insight from the various posts not only from Dell members but from regular KACE users.

So on to the tissue at hand...
I have Googled this for almost 2 weeks and cannot find a way to do it so I'm hoping one of you may be of assistance

I'm trying to finish a vbscript/hta that prompts for department name then searches Active Directory for available name, and names the computer based on that free name.

Naming convention is SF-ENG-L01, SF-ENG-L02, and so on, naming convention is: Location-Department-Laptop/Desktop##

Example:

3 computers accounts exist in Engineering OU, SF-ENG-L01, SF-ENG-L02, and SF-ENG-L04.

KACE 2000 completes Windows 7 install, final post install task is this all in one vbscript.:

1. post-install vbscript /HTA prompt drop-down asks for department, in this case example is ENG (Engineering)
2. Script queries active directory and notices that SF-ENG-L03 has not been used yet as a name, so assigns strComputer = "SF-ENG-L03"
3. strComputer is used as netdom argument via wshell.run()

I've got everything working except for step 2. I think I should be using an LDAP filter paired with a right() command to split the numbers at the end and compare the difference but I can't seem to get it. Am I making this more complicated than it should be?

I just need a hint, I'm so close. Thanks so much for any help you can provide.

0 Comments   [ + ] Show comments

Answers (2)

Posted by: dchristian 13 years ago
Red Belt
0
Hey Luiznbecky,

I get where your going with this.

One thing i can see with this script is how do you handle machines that have been re-imaged?

If the machine was eng-01, and gets re-imaged it probably shouldn't be changed to eng-02.

wsname handles this by setting up a database and tracking the machines mac address.

Maybe their article will point you in the right direction.

[link]http://mystuff.clarke.co.nz/MyStuff/vbsstuff.asp?func=WSNameNamingwithSQL&Title=Using%20SQL%20to%20Generate%20a%20Self%20Incrementing%20Computer%20Naming%20System#WSNameNamingwithSQL[/link]
Posted by: CodyNguyen 13 years ago
Yellow Belt
0
Hello Luizbecky,
I have a script for your step 2. hope it works for you.

you can call this function and pass the prefix of the pc name. Remeber to replace your root domain in the LDAP.

StrAvailableName = FindAvailableName("SF-ENG-L")

Function FindAvailableName(StrPrefix)
'*****************************************
'* Search for an available computer name *
'*****************************************
Const ADS_SCOPE_SUBTREE = 2
Dim nCount, PCName,PCExist
Dim objConnection, objCommand,objRecordSet,PCVar

nCount = 1
PCName = StrPrefix & "0" & nCount
PCExist = False


Do Until PCExist
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

'Enter your LDAP search root for your domain here 'LDAP://dc=corp,dc=com'
objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://dc=corp,dc=com' WHERE objectCategory='computer' " & "AND name=' " & PCName & "'"
Set objRecordSet = objCommand.Execute

PCVar = ""
if not (objRecordSet.EOF And objRecordSet.BOF) Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
'WScript.Echo objRecordSet.Fields("ADsPath").Value
PCVar = objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop
nCount = nCount + 1
if nCount < 10 then
PCName = StrPrefix & "0" & nCount
else
PCName = StrPrefix & nCount
End If


IF PCVar = "" Then
PCExist = True
END IF


Loop

AvailablePCName = PCName

End Function
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ