Sign in to follow this  
Followers 0
JoshuaLoman

After using StringFormat, the script doesnt end anymore.

5 posts in this topic

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!

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by JoshuaLoman

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0