Jump to content

Sysprep Dynamic Computername based on AD enumeration


Recommended Posts

Hi guys,

Does anyone know of a script that I can use to do the following?

Enumerate an OU in AD for existing Computernames

E.G.:

SERVER1

SERVER2

SERVER3

Then name computer in sysprep to highest number + 1

Name Computer SERVER4

Thnaks for your assistance.

Link to comment
Share on other sites


From microsoft scriptcenter should list all computer in an OU, modify line 3 for you OU and domain

Const ADS_SCOPE_SUBTREE = 2

'set ADLOOKUP value to your ORG and OU
ADLOOKUP = "Select Name, Location from 'LDAP://OU=AA, DC=COMPANY, DC=com' "

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

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
ADLOOKUP _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...