![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Create mutiple PCs in the Domain using vbScripts 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" ) |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx Quote: > 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" > > ) > should be removed. Next, the first "On Error Resume Next" statement should be removed. I believe this is masking the problem, which is the following statement: Set objContainer = GetObject("LDAP://; & strContainer") This statement should be: Set objContainer = GetObject("LDAP://" & strContainer) Next, I would assign the value for the userAccountControl attribute. You have commented out two statements for this. The one you want is: objComputer.Put "userAccountControl", _ ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT This statement should follow the one that assigns a value to the sAMAccountName attribute, before the SetInfo statement. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts Richard, Thank you very much for your response. The script work, but can you tell me why I am getting the " Unable to set properties for computer test1" error but it creates the computer account. Any I dea? Do I need to specify the properties for this, if so how do I do it? Thanks, Jeff "Richard Mueller [MVP]" wrote: Quote: > > "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx Quote: > > 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" > > > > ) > > > First, if the parentheses surronding the code are part of the script they > should be removed. Next, the first "On Error Resume Next" statement should > be removed. I believe this is masking the problem, which is the following > statement: > > Set objContainer = GetObject("LDAP://; & strContainer") > > This statement should be: > > Set objContainer = GetObject("LDAP://" & strContainer) > > Next, I would assign the value for the userAccountControl attribute. You > have commented out two statements for this. The one you want is: > > objComputer.Put "userAccountControl", _ > ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT > > This statement should follow the one that assigns a value to the > sAMAccountName attribute, before the SetInfo statement. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts Your script traps two possible errors. If an error is raised creating the computer object, it displays the message "Unable to create computer test1". You did not get that error, so the object was successfully created. Next, if the error message you mentioned is displayed, that means the error was raised when the SetInfo method was invoked. This means that the value of either the sAMAccountName or userAccountControl attribute could not be set (assuming you uncommented the statement that assigns a value to userAccountControl). One possible cause of the error is that another object has sAMAccountName equal to "test1$". The value must be unique in the domain. Another possibility is that you lack permissions to create the object. Also, if you added a statement to assign a value to userAccountControl, you may have coded a syntax error. If you are sure that no other object in your domain has sAMAccountName equal to "test1$", and you know you have permission to create computer objects, reply with the exact code you are using. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message news:C6F97B3F-E7E6-4877-9462-4107427F59E0@xxxxxx Quote: > Richard, > Thank you very much for your response. The script work, but can you tell > me > why I am getting the " Unable to set properties for computer test1" error > but it creates the computer account. Any I dea? Do I need to specify the > properties for this, if so how do I do it? > > Thanks, > Jeff > > > "Richard Mueller [MVP]" wrote: > Quote: >> >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message >> news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx Quote: >> > 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" >> > >> > ) >> > >> First, if the parentheses surronding the code are part of the script they >> should be removed. Next, the first "On Error Resume Next" statement >> should >> be removed. I believe this is masking the problem, which is the following >> statement: >> >> Set objContainer = GetObject("LDAP://; & strContainer") >> >> This statement should be: >> >> Set objContainer = GetObject("LDAP://" & strContainer) >> >> Next, I would assign the value for the userAccountControl attribute. You >> have commented out two statements for this. The one you want is: >> >> objComputer.Put "userAccountControl", _ >> ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT >> >> This statement should follow the one that assigns a value to the >> sAMAccountName attribute, before the SetInfo statement. >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net >> -- >> >> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts Your are right, it's a permission issue. I ran the script as a domain administrator and it ran with no error. Your awesome... One last thing, in the code, thee is a line that say "strContainer ="ou=SAMPLE_OU,dc=XYZ,dc=org" How can I tell the script to create the computer account in the Sub OU of the "SAMPLE" OU? The way I have my Containers setup is for example "Sample" OU is the parent container then I have sub OUs. How can I tell the script to put on the sub OUs of the "Sample" OU? I hope this makes sence Thank you, Jeff "Richard Mueller [MVP]" wrote: Quote: > Your script traps two possible errors. If an error is raised creating the > computer object, it displays the message "Unable to create computer test1". > You did not get that error, so the object was successfully created. Next, if > the error message you mentioned is displayed, that means the error was > raised when the SetInfo method was invoked. This means that the value of > either the sAMAccountName or userAccountControl attribute could not be set > (assuming you uncommented the statement that assigns a value to > userAccountControl). > > One possible cause of the error is that another object has sAMAccountName > equal to "test1$". The value must be unique in the domain. Another > possibility is that you lack permissions to create the object. Also, if you > added a statement to assign a value to userAccountControl, you may have > coded a syntax error. > > If you are sure that no other object in your domain has sAMAccountName equal > to "test1$", and you know you have permission to create computer objects, > reply with the exact code you are using. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > news:C6F97B3F-E7E6-4877-9462-4107427F59E0@xxxxxx Quote: > > Richard, > > Thank you very much for your response. The script work, but can you tell > > me > > why I am getting the " Unable to set properties for computer test1" error > > but it creates the computer account. Any I dea? Do I need to specify the > > properties for this, if so how do I do it? > > > > Thanks, > > Jeff > > > > > > "Richard Mueller [MVP]" wrote: > > Quote: > >> > >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > >> news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx > >> > 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" > >> > > >> > ) > >> > > >> > >> First, if the parentheses surronding the code are part of the script they > >> should be removed. Next, the first "On Error Resume Next" statement > >> should > >> be removed. I believe this is masking the problem, which is the following > >> statement: > >> > >> Set objContainer = GetObject("LDAP://; & strContainer") > >> > >> This statement should be: > >> > >> Set objContainer = GetObject("LDAP://" & strContainer) > >> > >> Next, I would assign the value for the userAccountControl attribute. You > >> have commented out two statements for this. The one you want is: > >> > >> objComputer.Put "userAccountControl", _ > >> ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT > >> > >> This statement should follow the one that assigns a value to the > >> sAMAccountName attribute, before the SetInfo statement. > >> > >> -- > >> Richard Mueller > >> MVP Directory Services > >> Hilltop Lab - http://www.rlmueller.net > >> -- > >> > >> > >> > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts You must bind to the OU or container where the object is to be created. The value of the variable strContainer should be the Distinguished Name of this OU or container. If you want to create the object in a sub (child) OU, assign the full Distinguished Name of the sub OU. For example, of the ou "ou=Sample OU" is a child of "ou=Sample_OU,dc=XYZ,dc=org", then you want: strContainer = "ou=Sample OU,ou=Sample_OU,dc=XYZ,dc=org" I hope this helps. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message news:44E09BA2-28BD-45C3-B0A4-1516B83E79E1@xxxxxx Quote: > Your are right, it's a permission issue. I ran the script as a domain > administrator and it ran with no error. Your awesome... One last thing, in > the code, thee is a line that say > "strContainer ="ou=SAMPLE_OU,dc=XYZ,dc=org" How can I tell the script to > create the computer account in the Sub OU of the "SAMPLE" OU? The way I > have > my Containers setup is for example > "Sample" OU is the parent container then I have sub OUs. How can I tell > the > script to put on the sub OUs of the "Sample" OU? I hope this makes sence > > Thank you, > Jeff > > > "Richard Mueller [MVP]" wrote: > Quote: >> Your script traps two possible errors. If an error is raised creating the >> computer object, it displays the message "Unable to create computer >> test1". >> You did not get that error, so the object was successfully created. Next, >> if >> the error message you mentioned is displayed, that means the error was >> raised when the SetInfo method was invoked. This means that the value of >> either the sAMAccountName or userAccountControl attribute could not be >> set >> (assuming you uncommented the statement that assigns a value to >> userAccountControl). >> >> One possible cause of the error is that another object has sAMAccountName >> equal to "test1$". The value must be unique in the domain. Another >> possibility is that you lack permissions to create the object. Also, if >> you >> added a statement to assign a value to userAccountControl, you may have >> coded a syntax error. >> >> If you are sure that no other object in your domain has sAMAccountName >> equal >> to "test1$", and you know you have permission to create computer objects, >> reply with the exact code you are using. >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net >> -- >> >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message >> news:C6F97B3F-E7E6-4877-9462-4107427F59E0@xxxxxx Quote: >> > Richard, >> > Thank you very much for your response. The script work, but can you >> > tell >> > me >> > why I am getting the " Unable to set properties for computer test1" >> > error >> > but it creates the computer account. Any I dea? Do I need to specify >> > the >> > properties for this, if so how do I do it? >> > >> > Thanks, >> > Jeff >> > >> > >> > "Richard Mueller [MVP]" wrote: >> > >> >> >> >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message >> >> news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx >> >> > 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" >> >> > >> >> > ) >> >> > >> >> >> >> First, if the parentheses surronding the code are part of the script >> >> they >> >> should be removed. Next, the first "On Error Resume Next" statement >> >> should >> >> be removed. I believe this is masking the problem, which is the >> >> following >> >> statement: >> >> >> >> Set objContainer = GetObject("LDAP://; & strContainer") >> >> >> >> This statement should be: >> >> >> >> Set objContainer = GetObject("LDAP://" & strContainer) >> >> >> >> Next, I would assign the value for the userAccountControl attribute. >> >> You >> >> have commented out two statements for this. The one you want is: >> >> >> >> objComputer.Put "userAccountControl", _ >> >> ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT >> >> >> >> This statement should follow the one that assigns a value to the >> >> sAMAccountName attribute, before the SetInfo statement. >> >> >> >> -- >> >> Richard Mueller >> >> MVP Directory Services >> >> Hilltop Lab - http://www.rlmueller.net >> >> -- >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Create mutiple PCs in the Domain using vbScripts Thank you Very much for your Help Sir, it worked. I had it backwards... THanks again. "Richard Mueller [MVP]" wrote: Quote: > You must bind to the OU or container where the object is to be created. The > value of the variable strContainer should be the Distinguished Name of this > OU or container. If you want to create the object in a sub (child) OU, > assign the full Distinguished Name of the sub OU. For example, of the ou > "ou=Sample OU" is a child of "ou=Sample_OU,dc=XYZ,dc=org", then you want: > > strContainer = "ou=Sample OU,ou=Sample_OU,dc=XYZ,dc=org" > > I hope this helps. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > news:44E09BA2-28BD-45C3-B0A4-1516B83E79E1@xxxxxx Quote: > > Your are right, it's a permission issue. I ran the script as a domain > > administrator and it ran with no error. Your awesome... One last thing, in > > the code, thee is a line that say > > "strContainer ="ou=SAMPLE_OU,dc=XYZ,dc=org" How can I tell the script to > > create the computer account in the Sub OU of the "SAMPLE" OU? The way I > > have > > my Containers setup is for example > > "Sample" OU is the parent container then I have sub OUs. How can I tell > > the > > script to put on the sub OUs of the "Sample" OU? I hope this makes sence > > > > Thank you, > > Jeff > > > > > > "Richard Mueller [MVP]" wrote: > > Quote: > >> Your script traps two possible errors. If an error is raised creating the > >> computer object, it displays the message "Unable to create computer > >> test1". > >> You did not get that error, so the object was successfully created. Next, > >> if > >> the error message you mentioned is displayed, that means the error was > >> raised when the SetInfo method was invoked. This means that the value of > >> either the sAMAccountName or userAccountControl attribute could not be > >> set > >> (assuming you uncommented the statement that assigns a value to > >> userAccountControl). > >> > >> One possible cause of the error is that another object has sAMAccountName > >> equal to "test1$". The value must be unique in the domain. Another > >> possibility is that you lack permissions to create the object. Also, if > >> you > >> added a statement to assign a value to userAccountControl, you may have > >> coded a syntax error. > >> > >> If you are sure that no other object in your domain has sAMAccountName > >> equal > >> to "test1$", and you know you have permission to create computer objects, > >> reply with the exact code you are using. > >> > >> -- > >> Richard Mueller > >> MVP Directory Services > >> Hilltop Lab - http://www.rlmueller.net > >> -- > >> > >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > >> news:C6F97B3F-E7E6-4877-9462-4107427F59E0@xxxxxx > >> > Richard, > >> > Thank you very much for your response. The script work, but can you > >> > tell > >> > me > >> > why I am getting the " Unable to set properties for computer test1" > >> > error > >> > but it creates the computer account. Any I dea? Do I need to specify > >> > the > >> > properties for this, if so how do I do it? > >> > > >> > Thanks, > >> > Jeff > >> > > >> > > >> > "Richard Mueller [MVP]" wrote: > >> > > >> >> > >> >> "JeporoxAKO" <JeporoxAKO@xxxxxx> wrote in message > >> >> news:CC72CE3B-DA49-48EA-AC0C-1CCEA01C8157@xxxxxx > >> >> > 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" > >> >> > > >> >> > ) > >> >> > > >> >> > >> >> First, if the parentheses surronding the code are part of the script > >> >> they > >> >> should be removed. Next, the first "On Error Resume Next" statement > >> >> should > >> >> be removed. I believe this is masking the problem, which is the > >> >> following > >> >> statement: > >> >> > >> >> Set objContainer = GetObject("LDAP://; & strContainer") > >> >> > >> >> This statement should be: > >> >> > >> >> Set objContainer = GetObject("LDAP://" & strContainer) > >> >> > >> >> Next, I would assign the value for the userAccountControl attribute. > >> >> You > >> >> have commented out two statements for this. The one you want is: > >> >> > >> >> objComputer.Put "userAccountControl", _ > >> >> ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT > >> >> > >> >> This statement should follow the one that assigns a value to the > >> >> sAMAccountName attribute, before the SetInfo statement. > >> >> > >> >> -- > >> >> Richard Mueller > >> >> MVP Directory Services > >> >> Hilltop Lab - http://www.rlmueller.net > >> >> -- > >> >> > >> >> > >> >> > >> > >> > >> > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| What is the executable associated with running VBScripts? | VB Script | |||
| VBScripts in Vista | Vista General | |||
| I am trying to create a Domain Controller | Vista networking & sharing | |||
| I am trying to create a Domain Controller | Vista account administration | |||
| I am trying to create a Domain Controller | Vista networking & sharing | |||