JoshuaLoman Posted February 15, 2012 Posted February 15, 2012 I made an script to create users in Active Directory. This is a little part of a bigger script that also created shares etc etc. The users in active directory have to look like this: 12345001 12345002 ... 12345010 With the first script, when i create 10 users, the 10th user will be created like this: 123450010 instead of: 12345010 This is the first script: For $counter = 1 to $AantalAccs RunWait("psexec.exe \\dbase01 dsadd user CN=" & $klantnr & "00" & $counter & ",""OU=Online Users,DC=netvio,DC=nl"" -pwd " & $klantnr & "00" & $counter & " -upn """ & $klantnr & "00" & $counter & "@netvio.nl"" -desc """ & $Plaats & " - " & $Naam & """ -profile ""\\dbase01\profile$\" & $klantnr & "00" & $counter & """ -loscr """ & $klantnr & ".bat"" -memberof ""CN=" & $klantnr & ",OU=Online Users,DC=netvio,DC=nl""""","",@SW_HIDE) Next $AantalAccs = the number of accounts that have to be created $klantnr = the first 5 numbers of the username Now i have changed the script with the help of StringFormat, the users are created with the right usernames, but the problem is that my script now doesnt end anymore, it got stuck at a certain point. This happend after i have edited this part of the script. This is the second script: For $counter = 1 to $AantalAccs RunWait("psexec.exe \\dbase01 dsadd user CN=" & $klantnr & "" & StringFormat("%03d", $counter) & ",""OU=Online Users,DC=netvio,DC=nl"" -pwd " & $klantnr & "" & StringFormat("%03d", $counter) & " -upn """ & $klantnr & "" & StringFormat("%03d", $counter) & "@netvio.nl"" -desc """ & $Plaats & " - " & $Naam & """ -profile ""\\dbase01\profile$\" & $klantnr & "" & StringFormat("%03d", $counter) & """ -loscr """ & $klantnr & ".bat"" -memberof ""CN=" & $klantnr & ",OU=Online Users,DC=netvio,DC=nl""""","",@SW_HIDE) Next I cant get it figured out, hope that you can help!
water Posted February 15, 2012 Posted February 15, 2012 Too many """""""" maybe? & "" &definitely just adds a string with length 0 to the command. May I recommend my Active Directory UDF to create users etc? You get better error handling and a lot of additional functions. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
JoshuaLoman Posted February 15, 2012 Author Posted February 15, 2012 (edited) The strange thing is when i run this script, it creates the users perfectly, it seems that it gets stuck when it is ready creating the users. without the "" i dont know how to get the stringformat to work. Maybe you can correct my code? Thanks for the recommendation, looks very good, but ive already sorted it out this way and it does everything it needs to do. Edit: hmm changed the code back to the code of the first script, but still the same problem.. very strange since i have not changed other code, maybe a typing mistake.. Edited February 15, 2012 by JoshuaLoman
water Posted February 15, 2012 Posted February 15, 2012 How about this? It outputs the string to use with RunWait: Global $AantalAccs = 1 Global $klantnr ="klantnr", $Plaats = "Plaats", $Naam = "Naam" For $counter = 1 To 1 Consolewrite('psexec.exe dbase01 dsadd user "CN=' & $klantnr & StringFormat("%03d", $counter) & ',OU=Online Users,DC=netvio,DC=nl" -pwd ' & $klantnr & StringFormat("%03d", $counter) & ' -upn "' & $klantnr & StringFormat("%03d", $counter) & '@netvio.nl" -desc "' & $Plaats & ' - ' & $Naam & '" -profile "dbase01profile$' & $klantnr & StringFormat("%03d", $counter) & '" -loscr "' & $klantnr & '.bat" -memberof "CN=' & $klantnr & ',OU=Online Users,DC=netvio,DC=nl"' & @CRLF) Next My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
JoshuaLoman Posted February 15, 2012 Author Posted February 15, 2012 Hmm thanks for the help but i have found an other piece of code where the problem is in.. now i have to solve that, too bad scite doesnt give me an error haha
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now