xinx Posted March 13, 2012 Posted March 13, 2012 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
DW1 Posted March 13, 2012 Posted March 13, 2012 Try and change ProgressSet($i, "User: " & $record[1] & " successfully added") to ProgressSet($i/(UBound($csv) - 1) * 100, "User: " & $record[1] & " successfully added") AutoIt3 Online Help
xinx Posted March 13, 2012 Author Posted March 13, 2012 (edited) Genius sir! 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 March 13, 2012 by xinx
UEZ Posted March 14, 2012 Posted March 14, 2012 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
water Posted March 14, 2012 Posted March 14, 2012 (edited) 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 March 14, 2012 by water 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
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