![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Probably simple for someon who knows what they are doing. Hi, I need some help writing a script that will take an input of the users ID (without the full DN) and then lookup that users manager and then lookup that managers email address and return that email address. Is that easy? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Probably simple for someon who knows what they are doing. Gunna wrote: Quote: > Hi, I need some help writing a script that will take an input of the > users > ID (without the full DN) and then lookup that users manager and then > lookup > that managers email address and return that email address. > > Is that easy? object to convert the "pre-Windows 2000 logon name" (this is probably what you mean by the user ID) into the Distinguished Name (DN). This allows you to bind to the user object with the LDAP provider and retrieve the value of the "manager" attribute. This value is the DN of the manager of ther user, which can be used to bind to the manager user object and retrieve the value of the "mail" attribute of the manager. The "mail" attribute corresponds to the field labeled "E-mail" on the "General" tab in ADUC. For example: ============= ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Determine DNS name of domain from RootDSE. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use the NameTranslate object to find the NetBIOS domain name from the ' DNS domain name. Set objTrans = CreateObject("NameTranslate") objTrans.Init ADS_NAME_INITTYPE_GC, "" objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) ' Prompt for "pre-Windows 2000 logon name". strNTName = InputBox("Enter UserID") ' Use the Set method to specify the NT format of the user name. ' Trap error if user does not exist. On Error Resume Next objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "User " & strNTName & " does not exist" Wscript.Quit End If On Error GoTo 0 ' Use the Get method to retrieve the RPC 1779 Distinguished Name. strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to the user object. Set objUser = GetObject("LDAP://" & strUserDN) ' Retrieve DN of manager of user. strManagerDN = objUser.manager ' Bind to the manager user object. Set objManager = GetObject("LDAP://" & strManagerDN) ' Retrieve email address of manager. strEmail = objManager.mail Wscript.Echo "Email address of manager: " & strEmail ======== See this link for more information on using NameTranslate: http://www.rlmueller.net/NameTranslateFAQ.htm An alternative would be to use ADO to retrieve the DN of the user with the given "pre-Windows 2000 logon name" (actually, the value of the sAMAccountName attribute), then use ADO again to retrieve the mail attribute of the user whose directReports attribute matches the DN of the user. That doesn't seem easier to me. It would be if we started with the DN of the user, however. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Probably simple for someon who knows what they are doing. Ok great. I altered it a little to remove the popups, also I hard coded a user ID for now and the very end it takes the email address it learnt and sends an email to the users manager. My next question is how can I put this into a html page so when a user clicks a link this script is executed? Here is my altered script: ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Determine DNS name of domain from RootDSE. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use the NameTranslate object to find the NetBIOS domain name from the ' DNS domain name. Set objTrans = CreateObject("NameTranslate") objTrans.Init ADS_NAME_INITTYPE_GC, "" objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) ' Prompt for "pre-Windows 2000 logon name". ' fullstrNTName = InputBox("Enter UserID") 'strNTName=(Mid(fullstrNTName, 6, 999)) strNTName="z57354a" ' Wscript.echo "Extracted user is " & strNTName ' Use the Set method to specify the NT format of the user name. ' Trap error if user does not exist. On Error Resume Next objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName If (Err.Number <> 0) Then On Error GoTo 0 ' Wscript.Echo "User " & strNTName & " does not exist" Wscript.Quit End If On Error GoTo 0 ' Use the Get method to retrieve the RPC 1779 Distinguished Name. strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to the user object. Set objUser = GetObject("LDAP://" & strUserDN) ' Retrieve DN of manager of user. strManagerDN = objUser.manager ' Bind to the manager user object. Set objManager = GetObject("LDAP://" & strManagerDN) ' Retrieve email address of manager. strEmail = objManager.mail ' Wscript.Echo "Email address of manager: " & strEmail Set objEmail = CreateObject("CDO.Message") objEmail.From = "sender@xxxxxx" objEmail.To = strEmail objEmail.Subject = "Alert Test" objEmail.Textbody = "Server1 is no longer accessible over the network." objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _ "mailhost.kcc.com" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| What is a simple way to fax! | Vista print fax & scan | |||
| im sure it has to be simple | Vista mail | |||
| Probably simple but... | Vista Games | |||
| simple help | Vista General | |||
| Simple Types | PowerShell | |||