none
I need help with a VBS SCript that writes data in AD variables for users RRS feed

  • Question

  • Hello, I have been working on a script for several hours and it still does'nt works. I'm slowly but surely becoming more and more desperate. 

    The scritp does that , or should do that 

    1- Read a csv file : there is 5 datas in the file for each users, datas parsed with ";".  Sp 5 dataas per lign, 
    ex: aleroy;4181234567;2345678;;;
    you can a a lign that looks like this : aleroy;;;;;
    the data will only be written if there is one in the file ( first one obviously does not count cause it's the AD username
    2- Like I said, it will overwrite the data in the AD if theres one in the file, otherwise, it will loop on the next user

    I'm not a programmer , so I have a lot of problem making it work.  I have corrected a few bugs, the .vbs runs correctly now, but does not write anything

    Heres is the compete script I made. If you are good in VBS, please help me on that one :) 

    Const FLAT_FILE_DELIMITER = ";"
    Const ForReading = 1 'les modes d'ouverture possible du fichier
    Const sdnDC = "DC=03QS,DC=LOCAL"'pour identifier le nom de domaine vers lequel on veut importer

    Dim adoCSVConnection, adoCSVRecordSet, strPathToTextfile
    'Où se trouve le fichier d'export
    Dim FlatFilePath: FlatFilePath = "C:\ImportBottin.csv" 
    Dim strCSVFile
    Dim FileSystem
    Dim LigneCI
    dim username, mobile, pager, telephonenumber, fax

    '***************************************************************************
    'On s'assure que le fichier de résultats  a bien été généré et transféré 
    Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")

    If FileSystem.FileExists(FlatFilePath) = FALSE then
    'Logguer "Le fichier " &FlatFilePath& " n'a pas pu être trouvé"
    Set FileSystem = Nothing
    WScript.quit()
    End if
    '***************************************************************************

    ' Specify CSV file name.
    Set objTextFile = FileSystem.OpenTextFile(FlatFilePath, ForReading)

    Set objConnection = CreateObject("ADODB.Connection")  
    objConnection.Open "Provider=ADsDSOObject;"   

    '***************************************************************************

    Do While objTextFile.AtEndOfStream <> true
    LigneCI = objTextFile.Readline 
    p1=Instr (LigneCI, FLAT_FILE_DELIMITER)

    if p1 > 0 then
    'test pour voir ce que contient LigneCI

    arr = Split(LigneCI, FLAT_FILE_DELIMITER)

    'Wscript.echo arr(0)
    If UBound(arr) = 4 Then
    username = arr(0)
    mobile = arr(1)
    pager = arr(2)
    telephonenumber = arr(3)
    fax = arr(4) 'fax

    Set objCommand = CreateObject("ADODB.Command")  
    objCommand.ActiveConnection = objConnection
    objCommand.CommandText = "<LDAP://"& sdnDC & ">;(&(objectCategory=person)(objectClass=user)(userPrincipalName="& username &"));mobile,pager,telephonenumber,facsimileTelephoneNumber;subtree"  

    'Validation pour longueur max du champs AD
    REM mobile = Trim(Left(mobile, 50))
    REM pager = Trim(Left(pager, 50))
    REM telephonenumber = Trim(Left(telephonenumber, 50))
    REM fax = Trim(Left(fax, 50))

    UpdateAD objCommand, mobile, pager, telephonenumber, fax
    Else
    WScript.Echo "ligne en erreur : " & csTR(LigneCI)


    End If
    end if

    Loop

    '***************************************************************************

    Thank you very much 

    Thursday, April 23, 2015 6:29 PM

Answers

  • Don't take this bad, but I thought your answer was very condescending and a bit rude.

    I do not think that Bill's reply was either condescending or rude. It was factual. When you have a closer look at the posts in this forum then you will find that most of the replies come from a bunch of highly skilled professionals who spend quite a bit of their time answering scripting questions.

    Now let's draw a parallel. Let's assume that something is wrong with your car. Would you consider going to a repair garage and ask the mechanic what might be wrong and how to fox the problem? Not very likely. Yet this happens a lot in this forum: Instead of hiring a consultant, people with little coding background find a script somewhere on the net, then come here with a request for a professional to examine it in detail and make it work.

    If you come here with a specific question about your script then you will get a warm reception. Respondents will lean over backwards to help you. But they will not write (or rewrite) your script for you. They will not act as tutors for beginners either. Programming/scripting is a skill that requires a good deal of learning effort and practice. Some of us are prepared to acquire it. Others pay a trained consultant to do the job.


    Friday, April 24, 2015 1:39 PM

All replies

  • Your request is basically: "I have a script that doesn't work. I don't understand VBScript. Can someone fix this for me?"

    This forum is not the right place for this kind of request. The purpose of this forum is to help script writers get answers to specific scripting questions.

    If you need someone to fix code you don't understand, then you need to hire someone to help you.


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 23, 2015 6:36 PM
    Moderator
  • Hello,  I'm so sorry to have bothered you all with this. Like you said , I'm new to VBS, I did C and C++ a lot , but it was a longtime ago.  Anyhow, I was not asking for someone to FIX this for me but rather  get some advices on writing attributes to an Active Directory. 

    I'll try tio find someone elsewhere that could give me some hints about why the script I made doest not work. 

    Once again, I'm terribly sorry that I took some of your time so you could answer me back. 

    Sincerly,
    A guy trying to understand VBS on his own
    Don't take this bad, but I thought your answer was very condescending and a bit rude. Maybe I'm not at the right place for the kind of heklp I need, but I was only trying to get some advices, I never wanted to harrass anyone or making someone else do my work. In fact, it's a way to teach myself VBS and not a task I need to deliver at my work at a precise moment. 

    Have a good day

    Friday, April 24, 2015 12:49 PM
  • Don't take this bad, but I thought your answer was very condescending and a bit rude.

    I do not think that Bill's reply was either condescending or rude. It was factual. When you have a closer look at the posts in this forum then you will find that most of the replies come from a bunch of highly skilled professionals who spend quite a bit of their time answering scripting questions.

    Now let's draw a parallel. Let's assume that something is wrong with your car. Would you consider going to a repair garage and ask the mechanic what might be wrong and how to fox the problem? Not very likely. Yet this happens a lot in this forum: Instead of hiring a consultant, people with little coding background find a script somewhere on the net, then come here with a request for a professional to examine it in detail and make it work.

    If you come here with a specific question about your script then you will get a warm reception. Respondents will lean over backwards to help you. But they will not write (or rewrite) your script for you. They will not act as tutors for beginners either. Programming/scripting is a skill that requires a good deal of learning effort and practice. Some of us are prepared to acquire it. Others pay a trained consultant to do the job.


    Friday, April 24, 2015 1:39 PM
  • Recommendation:

    1.  Start by formatting the script so it is readable and properly indented.
    2.  Next determine what part is not working and try to make that bit a simple script that illustrates your problem. 
    3.  Post the complete text of any errors yo are getting.
    4,  Start simple and do a few lines at a time. 
    5.  Ask questions as you get stuck.

    We answer simple direct questions even for beginners.  As noted above we will not rewrite your script to your spec which is basically what you have asked.

    You asked for pointers.  Start with these and post back with new questions.


    \_(ツ)_/

    Friday, April 24, 2015 2:51 PM