Announcement

Collapse
No announcement yet.

Get email address from active directory and set it in Environment variable

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get email address from active directory and set it in Environment variable

    Hi everyone!

    I need help in writing a script that Get the email address of the user that logged on to the domain from active directory and set it as Environment variable .
    Thank,
    Aviv hassidim.

  • #2
    Re: Get email address from active directory and set it in Environment variable

    I suspect a combination of results from
    http://www.google.co.uk/search?q=scr...w=1454&bih=834
    and
    http://www.google.co.uk/search?q=scr...w=1454&bih=834

    will solve your problem. Not knowing which OS we are talking about (is Powershell an option) prevents a more detailed solution
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Get email address from active directory and set it in Environment variable

      Use SetEnv to set environment variable
      use AdFind to get AD data.

      sample batch,
      Code:
      ::
      :: Download AdFind.zip (by Joe Richards “joeware”) 
      :: from http://www.joeware.net/freetools
      :: extract AdFind.exe
      
      ::
      :: Download SetEnv_Setup (by Jonathan “Darka” Wilkes) 
      :: from http://debugspy.com
      :: use a tool like 7-zip to extract SetEnv.exe
      :: from the setup exe file. SetEnv.exe is a standalone utility 
      :: you do not have to run the setupfile.
      ::
      :: SetEnv creates/modify or delete environment variables. It
      :: then broadcasts a WM_SETTINGCHANGE to all of the windows in
      :: the system notifying running applications of our change.
      :: Note, this will not update the environment variable for running
      :: scripts and dos prompts that already were running before the
      :: SetEnv command. Running scripts and dos prompts needs to be
      :: restarted. Any program you open will show the new variable/value.
      
      ::
      :: place the files SetEnv.exe and AdFind.exe
      :: in the batch folder
      
      
      @echo off
      
      Set "varName=SMTP1"
      
      pushD %0\..
      
      :: utilities
      Set AdFind=AdFind.exe
      Set SetEnv=SetEnv.exe
      
      Set AdFindFilter=-default -f "&(objectcategory=person)(samaccountname=%USERNAME%)"
      
      for /f "tokens=2 delims=:" %%* in (
         '%AdFind% %AdFindFilter% -list -nodn proxyAddresses ^|findstr /b "SMTP:.*@.*"'
      ) do set %varName%=%%* && %SetEnv% -ua "%varName%" "%%*"
      
      popD
      
      goto :EOF
      /Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Get email address from active directory and set it in Environment variable

        Thank U all guys...
        Someone wrote for me a litle dot net 4 program that does it
        i have applay it by group policy as a scheduled task on startup of any user and it work.
        if u want to use it u need to install net framework 4 before.

        Thank,

        Aviv Hassidim
        Attached Files

        Comment

        Working...
        X