Jump to content
Sign in to follow this  
xinx

Anyway to make ProgressOn work for adding users into AD from a csv file

Recommended Posts

xinx

Hi all.

The following script gets a list of users from a csv file and then adds them into Active Directory.

$SelectedFile = "C:\Temp\Users.csv"
$csv = 0
_FileReadToArray($SelectedFile, $csv)
ProgressOn("Csv import", "Adding and creating users", "Please wait...", 16)
For $i=1 to Ubound($csv)-1
  Sleep(200)
  $record=StringSplit($csv[$i],",")
  $sCommonName = $record[3] & " " & $record[2]
  $sUser = $record[1]
  _AD_Open()
    $iValue = _AD_CreateUser($sOU, $record[1], $sCommonName)
  _AD_Close()
  ProgressSet($i, "User: " & $record[1] & " successfully added")
  Sleep(200)
Next
  ProgressSet(100, "Users imported successfully.")
  Sleep(750)
  ProgressOff()

This works, however what I am trying to achieve is a more accurate percentage bar. Somehow, the script should work out the amount of lines in the csv file, turn the number of lines into 100% and for each user move the percent bar. I.e., if there were 100 users, the percent bar would move by 10% for every user added.

Any help greatly appreciated. Although all I can offer is a smiley face :oops:

Share this post


Link to post
Share on other sites
xinx

Genius sir! :oops: Thank you. And love the profile pic btw.

Edit: I know it probably seemed like a simple math equation, but math is not my strong point. Nor is anything really!

Edited by xinx

Share this post


Link to post
Share on other sites
UEZ

I wrote some time ago some AD Tools. Might be useful for you!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
water

To enhance performance I would move some of the code outside of the loop. Plus some error checking might be helpful.

#include <AD.au3>
#include <file.au3>
Global $SelectedFile = "C:TempUsers.csv"
Global $sOU = "", $csv
_FileReadToArray($SelectedFile, $csv)
If @error Then Exit MsgBox(16, "Adding and creating users", "Error " & @error & " reading file " & $SelectedFile)
_AD_Open()
If @error Then Exit MsgBox(16, "Adding and creating users", "Error " & @error & " opening conection to Active Directory")
ProgressOn("Csv import", "Adding and creating users", "Please wait...", 16)
For $i = 1 To UBound($csv) - 1
    ; Sleep(200) ; Not needed
    $record = StringSplit($csv[$i], ",")
    $sCommonName = $record[3] & " " & $record[2]
    $sUser = $record[1]
    $iValue = _AD_CreateUser($sOU, $record[1], $sCommonName)
    If @error Then MsgBox(16, "Adding and creating users", "Error " & @error & " when creating user " & $record[1] & " - " & $sCommonName)
    ProgressSet($i, "User: " & $record[1] & " successfully added")
    ; Sleep(200) ; Not needed
Next
_AD_Close()
ProgressSet(100, UBound($csv) - 1 & " users imported successfully.")
Sleep(750)
ProgressOff()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

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  

  • Similar Content

    • Trinnon
      By Trinnon
      I have a question about the @error logging features in _AD_CreateUser.  Hopefully I am just missing something obvious.
      In my app I am creating a user if it does not exist then manipulating some attributes. 
      If the user does exist I would then call another function to remove groups from the user and modify some attributes.
      My question is...
      If the user already Exists, the _AD_CreateUser option gives $iValue = 0 and @error = 0.
      How can @error = 1 for the condition that the user already exists?
       
      I copied a small ship of the code in question along with my full .au3. 
      I am using AD UDF 1.4.9.0 (Water, thanks for the awesome work on this!!!).
      $iValue = _AD_CreateUser ($sOU, $sUser, $sCN)
      If $iValue = 1 Then
            _FileWriteLog ($Log, "Func UserCheck() - User '" & $sUser & "' successfully created ==> Calling UserAttribsNewUser Function.")
            Call ("NewUser")
      ElseIf @error = 1 Then
            _FileWriteLog ($Log, $sUser & " already exists ==> Calling UserAttribsExistingUser Function.")
            Call ("ExistingUser")
       
      AccountSettingConfigurations-Test1.au3
       
    • water
      By water
      Extensive library to control and manipulate Microsoft Active Directory.

      Threads: Development - General Help & Support - Example Scripts - Wiki
      Previous downloads: 30467
       
      Known Bugs: (last changed: 2018-06-01)
      None  
      Things to come: (last changed: 2018-06-01)
      None
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • water
      By water
      ADAT is a tool to simplify common AD administration tasks. Every administration task has its own tab. It is easy to add new functions (tabs) to the tool. Some often used functions are already available: list users, computers, OUs. File ADAT.ini can be customized to hold the AD logon information if necessary.
      Known Bugs:
      2018-03-07: If the Script started from SciTE works but the "Process" button in the compiled exe does not do anything then please add the following line at the top of your script:
      #Au3Stripper_Ignore_Funcs=Process_Tab*
        BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
    • bouzzi
      By bouzzi
      Hi guys,
      I'm trying to make a script that could tell me, from a username list file,  if the username is active, inactive or not existant  in a multi-domain Active Directory....
      I found a few scripts giving me hints but I found nothing to help me to accomplish this task...
      Do you have any ideas !
      Thanks
      Bouzzi!
       
    • water
      By water
      On one/multiple big sheet(s) you get users (columns) and groups (rows). The list is sorted descending by number of members so you get the users with most groups and the groups with most members on top of the page. You can filter by (multiple) samaccountname(s), department or you can create your own LDAP query filter. You can filter the resulting list of groups using a Regular Expression.
      Version 2.0 uses maps so at the moment it requires the latest beta version of AutoIt!
      BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
×