Skip to content

VBS script for next available computer name in AD

Featured Replies

Hello Guys,

 

I have been suffering around for like 3 days on Forums and Google and it's killing me I almost clicked each google page what's starting with OSD SCCM VBS and Computername. I hope you can help me with my small issue.

 

I am trying to search trough AD for the Next available computer name. Example:

 

PC-001

PC-002

PC-004

PC-005

 

So when I deploy an Unknown System he should get OSDCOMPUTERNAME PC-003.

 

I have found some web service solutions for this problem but doesn't know really how to implement it with IIS and MDT.

 

If somebody has a nice tutorial it would be nice or else I prefer also a vbsscript for this. I already got a script that is looking if the computer is having minint I am using this for Known computers.

 

Here is also a script that is looking for the last computername but it's still not what I am looking for:

 

Const adUseClient = 3

strDept = InputBox("Enter Department","","DEPT")

Set objRootDSE = GetObject("LDAP://RootDSE")
strDomainDN = objRootDSE.Get("defaultNamingContext")

Set Conn = CreateObject("ADODB.Connection")
Set Comm = createobject("ADODB.Command")
Set RS = CreateObject("ADODB.Recordset")

strQuery = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & _
	   ">;(&(objectCategory=computer)(objectClass=computer)(name=" & strDept & "*));ADsPath,samAccountName;subtree"

Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
Conn.CursorLocation = adUseClient

Comm.ActiveConnection = Conn
Comm.Properties("Page Size") = 1000
Comm.CommandText = strQuery
Comm.Properties("Sort on") = "samAccountName"

Set rs = comm.Execute

While Not rs.EOF
  rs.movelast
  strComputer = rs("samAccountName")
  rs.MoveNext
Wend

 

I hope you guys can help me with this problem.

Thank you !

 

Greetz,

Zoran

  • Author

I am getting it a little bit with MDT and the web services from itxsolution. I am still struggling with the CustomSettings.ini I don't know how to get the information from the Web service.

 

Usage:

- GetADSite: Will find AD site for computer which is making the request

 

- OSD_GeneratePCName

 

When calling webservices it requires the following parameters:

  • DomainFQDN - domain where computer name is to be generated (NEEDS TO MATCH FqdnOfDomain from WebConfig)
  • ADSite - As web service initially tries to find nearest domain controller for client
  • Prefix - Computer name prefix for generating new name (i.e. ABC1- )
  • HubDC - domain controller name if no DC has been found for AD site specified (kidn'a failover) - must be from domain specified in domainFqdn param
  • OU - target OU for computer placing in format "OU=AAA,OU=BBB,DC=ABC,DC=com"

Can somebody explain it to me.

  • Author

Finally I got it working. Problem Solved :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.