Jump to content


zoranjukic

VBS script for next available computer name in AD

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.