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


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


Please log in to comment

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


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.

Answered 04/25/2011 by: dchristian
Red Belt

Please log in to comment
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 *
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
Do Until objRecordSet.EOF
'WScript.Echo objRecordSet.Fields("ADsPath").Value
PCVar = objRecordSet.Fields("ADsPath").Value
nCount = nCount + 1
if nCount < 10 then
PCName = StrPrefix & "0" & nCount
PCName = StrPrefix & nCount
End If

IF PCVar = "" Then
PCExist = True


AvailablePCName = PCName

End Function
Answered 08/19/2011 by: CodyNguyen
Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity