+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
Windows Thread, Entering email addresses for muliple users in Active Directory in Technical; Originally Posted by machin05 T Any pointers or example scripting will be of great help as my own scripting experience ...
  1. #16


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    Quote Originally Posted by machin05 View Post
    T

    Any pointers or example scripting will be of great help as my own scripting experience has been gathered on a very ad hoc basis.
    Can you not see the script that I posted?, you can save it as a .vbs file then run it on each OU by editing the text so that it suits your organisation.
    It does exactly what you want, we have our moodle fields populated this way.

  2. #17
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    Nice on CyberNerd, I've had a look at your script, and it looks like it would do the job apart from the fact our SAMAccountName values don't match up with our email address prefix. For example Steve Bull would have a SAMAccountName of s.bull but an email of sbull@schoolname.bham.sch.uk

    Is there anyway of tying this script in with an excel file that I could use to remover the full stops?

    Cheers,
    Will

  3. #18


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    I wrote you a shortened version:

    this bit sets the LDAP OU that you will search, you must change this:
    Code:
    Set objParent = GetObject("LDAP://OU=Year XX,DC=College,DC=internal")
    this bit says select 'users' rather than computers/groups
    Code:
    objparent.Filter = Array("user")
    for every user that has been selected
    Code:
    for each objUser in objParent
    tell me what is happening (commented out)
    Code:
      'Wscript.Echo "Modifying " & objUser.Get("sAMAccountName")
    then set teh 'mail' LDAP attribute to that of the accountname + email.address
    Code:
    	objUser.put "mail", objUser.Get("sAMAccountName") & "@email.address"
    write the info back to AD
    Code:
    objuser.Setinfo
    go do the next one
    Code:
    next

  4. #19


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    to select the sirname , the ldap attribute is 'sn'
    Code:
    objUser.Get("sn")
    to find the firstname, it is givenname
    Code:
    objUser.Get("givenname")
    so you just need a way of finding out how to get vbs to strip the first character from the givenname

  5. #20
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    986
    Thank Post
    58
    Thanked 165 Times in 117 Posts
    Rep Power
    68
    Quote Originally Posted by machin05 View Post
    Nice on CyberNerd, I've had a look at your script, and it looks like it would do the job apart from the fact our SAMAccountName values don't match up with our email address prefix. For example Steve Bull would have a SAMAccountName of s.bull but an email of sbull@schoolname.bham.sch.uk

    Is there anyway of tying this script in with an excel file that I could use to remover the full stops?

    Cheers,
    Will
    this line will give you the sAMAccountName without the "."

    $email = Replace(objUser.Get("sAMAccountName"),".",""))

  6. Thanks to penfold_99 from:

    CyberNerd (16th October 2008)

  7. #21
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by CyberNerd View Post
    to select the sirname , the ldap attribute is 'sn'
    Code:
    objUser.Get("sn")
    to find the firstname, it is givenname
    Code:
    objUser.Get("givenname")
    so you just need a way of finding out how to get vbs to strip the first character from the givenname
    You can use Left to do it i.e.

    Code:
    left(objUser.Get("givenname")
    ,1)
    but using replace to remove the "." is a cleaner way of coding imo.

  8. #22
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    Cheers for all the help chaps,

    I will definately have a look at the script you've detailed for me. Thanks very much.

    Quote Originally Posted by penfold_99 View Post
    this line will give you the sAMAccountName without the "."

    $email = Replace(objUser.Get("sAMAccountName"),".",""))
    Penfold, how can I incorporate that line into the script that is detailed above?

    Sorry for being a scripting simpleton!

    Cheers,
    Will

  9. #23
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    Ok, Ive modified the script but I'm getting an error on the first line, saying there is no such object. Can you tell me what the XX stands for in the example code?

    My first line reads:

    Code:
    Set objParent = GetObject("LDAP://OU=Moodle,OU=Staff,OU=Test,DC=lordswoodgirls,DC=school")
    Just to clarify, our domain is lordswoodgirls.school and the OU i'm trying this on is called Test, which is in an OU called Staff, which is in an OU call Moodle, which is in the root of the domain.

    Thanks again,
    Will

  10. #24
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    It seems as soon as I post on here, I realise what a moron I'm being! I've sorted the script, I realise I had the OU's the worng way round!

    On the off change, is there anyway of forcing it all in lowercase? As it stands I've got an email addresses reading as SBull@schoolname.bham.sch.uk. assume it makes no difference, but I'm funny about things like that!

    For reference my script looks like this:

    Code:
    Set objParent = GetObject("LDAP://OU=Test,OU=Staff,OU=Moodle,DC=lordswoodgirls,DC=school")
    
    objparent.Filter = Array("user")
    
    
    
    for each objUser in objParent
    
      'Wscript.Echo "Modifying " & objUser.Get("sAMAccountName")
    
    	objUser.put "mail", left(objUser.Get("givenname"),1) & objUser.Get("sn") & "@lordswdg.bham.sch.uk"
    
    objuser.Setinfo
    
    next
    
    Wscript.Echo "Done ;)"

  11. #25

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Quote Originally Posted by apeo View Post
    You can use Left to do it i.e.

    Code:
    left(objUser.Get("givenname"),1)
    but using replace to remove the "." is a cleaner way of coding imo.
    replace is nice and works well in this specific case. The good thing about getting different examples is that it shows people other options. Our email addresses are of the form <initial>.<surname>@ etc and for this the "left" function is needed because samaccountname won't give you that at all.

  12. #26

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Quote Originally Posted by machin05 View Post
    On the off change, is there anyway of forcing it all in lowercase? As it stands I've got an email addresses reading as SBull@schoolname.bham.sch.uk. assume it makes no difference, but I'm funny about things like that!
    Use lcase:

    Code:
    objUser.put "mail", lcase(left(objUser.Get("givenname"),1) & objUser.Get("sn")) & "@lordswdg.bham.sch.uk"

  13. Thanks to srochford from:

    machin05 (16th October 2008)

  14. #27
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    Quote Originally Posted by srochford View Post
    Use lcase:

    Code:
    objUser.put "mail", lcase(left(objUser.Get("givenname"),1) & objUser.Get("sn")) & "@lordswdg.bham.sch.uk"
    Thanks a lot mate, perfect.

    One last question (maybe!), how could I incorporate this line of code for replacing the .

    Code:
    $email = Replace(objUser.Get("sAMAccountName"),".",""))
    Whereabouts does it need to go?

    Thanks again,
    Will

  15. #28
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by machin05 View Post
    Thanks a lot mate, perfect.

    One last question (maybe!), how could I incorporate this line of code for replacing the .

    Code:
    $email = Replace(objUser.Get("sAMAccountName"),".",""))
    Whereabouts does it need to go?

    Thanks again,
    Will
    Something like this i guess:

    Code:
    lcase(Replace(objUser.Get("sAMAccountName"),".","")))

  16. Thanks to apeo from:

    machin05 (16th October 2008)

  17. #29
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by srochford View Post
    replace is nice and works well in this specific case. The good thing about getting different examples is that it shows people other options. Our email addresses are of the form <initial>.<surname>@ etc and for this the "left" function is needed because samaccountname won't give you that at all.
    yeah i meant in this case its cleaner to use replace but the other option is always there

  18. #30
    machin05's Avatar
    Join Date
    Dec 2007
    Posts
    339
    Thank Post
    22
    Thanked 27 Times in 25 Posts
    Rep Power
    24
    Cheers everyone,

    Got it sorted and working. Have successfully changed all staff entries. Much appreciated.

    My final script looked like this:

    Code:
    Set objParent = GetObject("LDAP://OU=Staff,OU=Moodle,DC=lordswoodgirls,DC=school")
    
    objparent.Filter = Array("user")
    
    for each objUser in objParent
    
      'Wscript.Echo "Modifying " & objUser.Get("sAMAccountName")
     
    	objUser.put "mail", lcase(Replace(objUser.Get("sAMAccountName"),".","")) & "@lordswdg.bham.sch.uk"
    
    objuser.Setinfo
    
    next
    
    Wscript.Echo "Done ;)"
    Thanks again,
    Will



SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Cannot create users in Active Directory
    By WithoutMotive in forum Windows
    Replies: 17
    Last Post: 6th February 2009, 12:20 PM
  2. Active Directory-Script for Creating Bulk Users
    By calapso in forum How do you do....it?
    Replies: 8
    Last Post: 14th January 2009, 07:32 PM
  3. Importing new users into Active Directory
    By Mr_M_Cox in forum How do you do....it?
    Replies: 16
    Last Post: 4th November 2008, 12:36 PM
  4. Active directory email options
    By Shrimpersfan in forum Windows
    Replies: 4
    Last Post: 16th May 2008, 01:53 PM
  5. Replies: 2
    Last Post: 28th November 2007, 05:40 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •