![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | find a user in AD HI all, im not much of a scripting person so please help. Im trying to write a simple enough script to ask for a logon name, then search through AD and pull out some info on that user like email address etc. I've tried a few things and just cant get it to work. Here is what ive got so far: Const ADS_SCOPE_SUBTREE = 2 strNTName=InputBox("Please enter a username to search") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = ("ADsDSOObject") objConnection.Open "Active Directory Provider" objCommand.ActiveConnection = objConnection objCommand.CommandText = "SELECT samAccountName (same line)FROM 'LDAP://dc=domainname,dc=com' WHERE samAccountName = "'strNTName'" objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.Execute My problem in in the Select statement putting the users input into the statement. it doesnt like it. Can anyone help? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: find a user in AD "Gunna" <Gunna@xxxxxx> wrote in message news:FA79AA37-4836-4FF0-A442-B94143C5CF20@xxxxxx Quote: > HI all, im not much of a scripting person so please help. Im trying to > write > a simple enough script to ask for a logon name, then search through AD and > pull out some info on that user like email address etc. I've tried a few > things and just cant get it to work. Here is what ive got so far: > > Const ADS_SCOPE_SUBTREE = 2 > > strNTName=InputBox("Please enter a username to search") > > Set objConnection = CreateObject("ADODB.Connection") > Set objCommand = CreateObject("ADODB.Command") > objConnection.Provider = ("ADsDSOObject") > objConnection.Open "Active Directory Provider" > objCommand.ActiveConnection = objConnection > objCommand.CommandText = "SELECT samAccountName (same line)FROM > 'LDAP://dc=domainname,dc=com' WHERE samAccountName = "'strNTName'" > objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE > Set objRecordSet = objCommand.Execute > > My problem in in the Select statement putting the users input into the > statement. it doesnt like it. Can anyone help? objCommand.CommandText = "SELECT sAMAccountName " _ & "FROM 'LDAP://dc=domainname,dc=com' " _ & "WHERE sAMAccountName = '" & strNTName & "'" Also, it would be more efficient to use the NameTranslate object. See this link: http://www.rlmueller.net/NameTranslateFAQ.htm -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: find a user in AD Il giorno Sun, 30 Nov 2008 20:07:01 -0800, =?Utf-8?B?R3VubmE=?= <Gunna@xxxxxx> ha scritto: Quote: >HI all, im not much of a scripting person so please help. Im trying to write >a simple enough script to ask for a logon name, then search through AD and >pull out some info on that user like email address etc. I've tried a few >things and just cant get it to work. Here is what ive got so far: '************************************************ ' File: Visualizza dati di un utente.vbs ' Autore: Giovanni Cenati reventlov@xxxxxx ' '************************************************ Set WshShell = WScript.CreateObject("WScript.Shell") ' Ottiene il nome del dominio e dell'utente strDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%") strUser= WshShell.ExpandEnvironmentStrings("%USERNAME%") ' Chiede la userid da cercare (default: utente corrente) strUser = inputbox ("Quale utente vuoi cercare?", "Visualizza Dati Utente",strUser) if struser ="" then wscript.quit 'Se premuto annulla ' Si collega al server e richiede l'utente Set objDomain = GetObject("WinNT://" & strDomain) Set objUser = objDomain.GetObject("user", strUser) ' Estrae i dati dell'utente e li mette nella variabile Dati. Dati= "Userid: "& vbtab & objUser.Name & vbcrlf Dati= Dati & "Nome: " & Vbtab & objUser.FullName & vbcrlf Dati= Dati & "Descriz: " & vbtab & objUser.Description & vbcrlf Dati= Dati & "Ult. Accesso: " & vbtab & objUser.LastLogin & vbcrlf Dati= Dati & vbcrlf & "Gruppi di appartenenza:" & vbcrlf & vbcrlf ' Estrae i gruppi di appartenenza dell'utente For Each objGroup In objUser.Groups Dati= Dati & objGroup.Name & vbtab next ' Output dati. msgbox Dati,, "Dati dell'utente " & strUser & " (Dominio " & strDomain & ")" -- Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: find a user in AD "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:uQD0Ov2UJHA.4916@xxxxxx Quote: > > "Gunna" <Gunna@xxxxxx> wrote in message > news:FA79AA37-4836-4FF0-A442-B94143C5CF20@xxxxxx Quote: >> HI all, im not much of a scripting person so please help. Im trying to >> write >> a simple enough script to ask for a logon name, then search through AD >> and >> pull out some info on that user like email address etc. I've tried a few >> things and just cant get it to work. Here is what ive got so far: >> >> Const ADS_SCOPE_SUBTREE = 2 >> >> strNTName=InputBox("Please enter a username to search") >> >> Set objConnection = CreateObject("ADODB.Connection") >> Set objCommand = CreateObject("ADODB.Command") >> objConnection.Provider = ("ADsDSOObject") >> objConnection.Open "Active Directory Provider" >> objCommand.ActiveConnection = objConnection >> objCommand.CommandText = "SELECT samAccountName (same line)FROM >> 'LDAP://dc=domainname,dc=com' WHERE samAccountName = "'strNTName'" >> objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE >> Set objRecordSet = objCommand.Execute >> >> My problem in in the Select statement putting the users input into the >> statement. it doesnt like it. Can anyone help? > Try: > > objCommand.CommandText = "SELECT sAMAccountName " _ > & "FROM 'LDAP://dc=domainname,dc=com' " _ > & "WHERE sAMAccountName = '" & strNTName & "'" > > Also, it would be more efficient to use the NameTranslate object. See this > link: > > http://www.rlmueller.net/NameTranslateFAQ.htm > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > ============= ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 strNTName=InputBox("Please enter a username to search") ' 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") ' Initialize NameTranslate by locating the Global Catalog. objTrans.Init ADS_NAME_INITTYPE_GC, "" ' Use the Set method to specify the NT format of the object name. objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain ' Use the Get method to retrieve the RPC 1779 Distinguished Name. strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) ' Use the Set method to specify the NT format of the object name. objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName ' Use the Get method to retrieve the RPC 1779 Distinguished Name. strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to the user object in Active Directory with the LDAP provider. Set objUser = GetObject("LDAP://" & strUserDN) ========== You could hard code the NetBIOS name of the domain, but the above retrieves it programmatically. In my tests, NameTranslate is faster than using ADO to search. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #5 (permalink) |
| | Re: find a user in AD Thanks that works but how do I list the users Distinguished Name? "Reventlov" wrote: Quote: > Il giorno Sun, 30 Nov 2008 20:07:01 -0800, =?Utf-8?B?R3VubmE=?= > <Gunna@xxxxxx> ha scritto: Quote: > >HI all, im not much of a scripting person so please help. Im trying to write > >a simple enough script to ask for a logon name, then search through AD and > >pull out some info on that user like email address etc. I've tried a few > >things and just cant get it to work. Here is what ive got so far: > This uses adsi. > > '************************************************ > ' File: Visualizza dati di un utente.vbs > ' Autore: Giovanni Cenati reventlov@xxxxxx > ' > '************************************************ > Set WshShell = WScript.CreateObject("WScript.Shell") > > ' Ottiene il nome del dominio e dell'utente > strDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%") > strUser= WshShell.ExpandEnvironmentStrings("%USERNAME%") > > ' Chiede la userid da cercare (default: utente corrente) > strUser = inputbox ("Quale utente vuoi cercare?", "Visualizza Dati Utente",strUser) > if struser ="" then wscript.quit 'Se premuto annulla > > ' Si collega al server e richiede l'utente > Set objDomain = GetObject("WinNT://" & strDomain) > Set objUser = objDomain.GetObject("user", strUser) > > ' Estrae i dati dell'utente e li mette nella variabile Dati. > Dati= "Userid: "& vbtab & objUser.Name & vbcrlf > Dati= Dati & "Nome: " & Vbtab & objUser.FullName & vbcrlf > Dati= Dati & "Descriz: " & vbtab & objUser.Description & vbcrlf > Dati= Dati & "Ult. Accesso: " & vbtab & objUser.LastLogin & vbcrlf > Dati= Dati & vbcrlf & "Gruppi di appartenenza:" & vbcrlf & vbcrlf > > ' Estrae i gruppi di appartenenza dell'utente > For Each objGroup In objUser.Groups > Dati= Dati & objGroup.Name & vbtab > next > > ' Output dati. > msgbox Dati,, "Dati dell'utente " & strUser & " (Dominio " & strDomain & ")" > -- > Giovanni Cenati (Bergamo, Italy) > Write to "Reventlov" at katamail com > http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) > -- > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: find a user in AD Since you have the user object reference objUser, you can retrieve the Distinguished Name with: objUser.distinguishedName Using the syntax from the code supplied: Dati= Dati & "DN: " & Vbtab & objUser.distinguishedName & vbcrlf -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "Gunna" <Gunna@xxxxxx> wrote in message news:6E0A12CD-5E73-4879-929B-B780E5AB2AAC@xxxxxx Quote: > Thanks that works but how do I list the users Distinguished Name? > > "Reventlov" wrote: > Quote: >> Il giorno Sun, 30 Nov 2008 20:07:01 -0800, =?Utf-8?B?R3VubmE=?= >> <Gunna@xxxxxx> ha scritto: Quote: >> >HI all, im not much of a scripting person so please help. Im trying to >> >write >> >a simple enough script to ask for a logon name, then search through AD >> >and >> >pull out some info on that user like email address etc. I've tried a >> >few >> >things and just cant get it to work. Here is what ive got so far: >> This uses adsi. >> >> '************************************************ >> ' File: Visualizza dati di un utente.vbs >> ' Autore: Giovanni Cenati reventlov@xxxxxx >> ' >> '************************************************ >> Set WshShell = WScript.CreateObject("WScript.Shell") >> >> ' Ottiene il nome del dominio e dell'utente >> strDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%") >> strUser= WshShell.ExpandEnvironmentStrings("%USERNAME%") >> >> ' Chiede la userid da cercare (default: utente corrente) >> strUser = inputbox ("Quale utente vuoi cercare?", "Visualizza Dati >> Utente",strUser) >> if struser ="" then wscript.quit 'Se premuto annulla >> >> ' Si collega al server e richiede l'utente >> Set objDomain = GetObject("WinNT://" & strDomain) >> Set objUser = objDomain.GetObject("user", strUser) >> >> ' Estrae i dati dell'utente e li mette nella variabile Dati. >> Dati= "Userid: "& vbtab & objUser.Name & vbcrlf >> Dati= Dati & "Nome: " & Vbtab & objUser.FullName & vbcrlf >> Dati= Dati & "Descriz: " & vbtab & objUser.Description & vbcrlf >> Dati= Dati & "Ult. Accesso: " & vbtab & objUser.LastLogin & vbcrlf >> Dati= Dati & vbcrlf & "Gruppi di appartenenza:" & vbcrlf & vbcrlf >> >> ' Estrae i gruppi di appartenenza dell'utente >> For Each objGroup In objUser.Groups >> Dati= Dati & objGroup.Name & vbtab >> next >> >> ' Output dati. >> msgbox Dati,, "Dati dell'utente " & strUser & " (Dominio " & strDomain & >> ")" >> -- >> Giovanni Cenati (Bergamo, Italy) >> Write to "Reventlov" at katamail com >> http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) >> -- >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script to find all user and what PC they are logged into | VB Script | |||
| can't find user after importing xp backup | Vista file management | |||
| script to find a certain info about a user | PowerShell | |||
| get-qaduser to find disabled user | PowerShell | |||
| Find out where the user looged into | Vista General | |||