Create mutiple PCs in the Domain using vbScripts

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello all,

Does anyone has a sample script that basically creates multiple PCs in the
domain?
A text file contains all the PCs then the script reads it and add those pcs
that's in the text file to the domain. I found a sample but it is not working
properly. I've included the script that I am using which I got from the web.

Thank you in advance.
JB


(
Dim objFSO, strFilePath, objFile, strContainer
Dim objContainer, strComputerName, objComputer
On ERROR RESUME NEXT
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &H1000
Const ADS_UF_PASSWD_NOTREQD = &H20

'objComputer.Put "userAccountControl", _
'ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT

Const ForReading = 1


' Specify container where computer objects created.
strContainer ="ou=SAMPLE_OU,dc=XYZ,dc=org"
Set objContainer = GetObject("LDAP://; & strContainer")
' Specify the text file of computerNames.
strFilePath = "c:\Scripts\pc.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)

' Read each line of the file and create computer accounts.
Do Until objFile.AtEndOfStream
strComputerName = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputerName <> "") Then
On Error Resume Next
Set objComputer = objContainer.Create("computer", "cn=" _
& strComputerName)
If (Err.Number <> 0) Then
Wscript.Echo "Unable to create computer " & strComputerName
End If
On Error GoTo 0
objComputer.Put "sAMAccountName", strComputerName & "$"
'objComputer.Put "userAccountControl",
ADS_UF_WORKSTATION_TRUST_ACCOUNT
On Error Resume Next
objComputer.SetInfo
If (Err.Number <> 0) Then
Wscript.Echo "Unable to set properties for computer " _
& strComputerName
End If
On Error GoTo 0
End If
Loop

' Clean up.
objFile.Close
Wscript.Echo "Done"

)



.



Relevant Pages

  • Re: Create mutiple PCs in the Domain using vbScripts
    ... Does anyone has a sample script that basically creates multiple PCs in the ... Dim objContainer, strComputerName, objComputer ...
    (microsoft.public.scripting.vbscript)
  • Re: Create mutiple PCs in the Domain using vbScripts
    ... Does anyone has a sample script that basically creates multiple PCs in the ... Dim objContainer, strComputerName, objComputer ... Wscript.Echo "Unable to set properties for computer " _ ...
    (microsoft.public.scripting.vbscript)
  • Re: Create mutiple PCs in the Domain using vbScripts
    ... If you want to create the object in a sub OU, ... script to put on the sub OUs of the "Sample" OU? ... either the sAMAccountName or userAccountControl attribute could not be ... Dim objContainer, strComputerName, objComputer ...
    (microsoft.public.scripting.vbscript)
  • Re: script long service names
    ... No I have to start the service as well See my script. ... Dim strComputerName, strServiceName, intNumAttempts, ... Dim oSCM, oUtil, oParams, blnSuccess ...
    (microsoft.public.scripting.vbscript)
  • Re: create computer accounts in AD
    ... I would like the script to create mltiple computer account in AD. ... ' Bind to Active Directory, ... Dim objContainer, strComputerName, objComputer ...
    (microsoft.public.scripting.wsh)