Solved

Match AD account display name to PC name ??

Posted on 2009-03-31
1
550 Views
Last Modified: 2013-11-21
Anyone know of a way to map an AD user account Display Name field to the name of the last machine that user logged into?

What Id like to do is take all 44 users in my COT\Accounting security group in AD, and get their computer names.  SMS 2003 can show the username of last logged on user to a computer, but only shows the AD username.  

Even better would be to select the AD security group and the a script/utility can run on its membership, then output a list of last used computer.

Anyone have an idea if this is possible?
0
Comment
Question by:net1994
1 Comment
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 24045216
Hi, perhaps the easiest way would be to run a login script, which would update each users "Description", or maybe "Notes" field (in the Telephones tab) with the name of the computer they have just logged onto.  Then you can run a script at any time to query that user and see what the field holds.

This would be your login script.

Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = Mid(Split(objADSysInfo.Computername, ",")(0), 4)
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
objUser.Info = strComputer
'objUser.Description = strComputer
objUser.SetInfo
Set objUser = Nothing

And then you could use the below script to search the AD by samAccountName (the login name) and check that value.

Regards,

Rob.
strUser = InputBox("Enter a username to see which computer they last used:", "Username", "Enter login name")

If strUser <> "" Then

	strADSPath = Get_LDAP_User_Properties("user", "samAccountName", strUser, "adsPath")

	If Left(strADSPath, 7) = "LDAP://" Then

		Set objUser = GetObject(strADSPath)

		MsgBox "This user last logged onto " & objUser.Info

		Set objUser = Nothing

	Else

		MsgBox "Unable to find adsPath for " & strUser

	End If

End If
 

Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)

      

      ' This is a custom function that connects to the Active Directory, and returns the specific

      ' Active Directory attribute value, of a specific Object.

      ' strObjectType: usually "User" or "Computer"

      ' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.

      '				It filters the results by the value of strObjectToGet

      ' strObjectToGet: the value by which the results are filtered by, according the strSearchField.

      '				For example, if you are searching based on the user account name, strSearchField

      '				would be "samAccountName", and strObjectToGet would be that speicific account name,

      '				such as "jsmith".  This equates to "WHERE 'samAccountName' = 'jsmith'"

      '	strCommaDelimProps: the field from the object to actually return.  For example, if you wanted

      '				the home folder path, as defined by the AD, for a specific user, this would be

      '				"homeDirectory".  If you want to return the ADsPath so that you can bind to that

      '				user and get your own parameters from them, then use "ADsPath" as a return string,

      '				then bind to the user: Set objUser = GetObject("LDAP://" & strReturnADsPath)

      

      ' Now we're checking if the user account passed may have a domain already specified,

      ' in which case we connect to that domain in AD, instead of the default one.

      If InStr(strObjectToGet, "\") > 0 Then

            arrGroupBits = Split(strObjectToGet, "\")

            strDC = arrGroupBits(0)

            strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")

            strObjectToGet = arrGroupBits(1)

      Else

      ' Otherwise we just connect to the default domain

            Set objRootDSE = GetObject("LDAP://RootDSE")

            strDNSDomain = objRootDSE.Get("defaultNamingContext")

      End If
 

      strBase = "<LDAP://" & strDNSDomain & ">"

      ' Setup ADO objects.

      Set adoCommand = CreateObject("ADODB.Command")

      Set adoConnection = CreateObject("ADODB.Connection")

      adoConnection.Provider = "ADsDSOObject"

      adoConnection.Open "Active Directory Provider"

      adoCommand.ActiveConnection = adoConnection
 

 

      ' Filter on user objects.

      'strFilter = "(&(objectCategory=person)(objectClass=user))"

      strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"
 

      ' Comma delimited list of attribute values to retrieve.

      strAttributes = strCommaDelimProps

      arrProperties = Split(strCommaDelimProps, ",")
 

      ' Construct the LDAP syntax query.

      strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

      adoCommand.CommandText = strQuery

      ' Define the maximum records to return

      adoCommand.Properties("Page Size") = 100

      adoCommand.Properties("Timeout") = 30

      adoCommand.Properties("Cache Results") = False
 

      ' Run the query.

      Set adoRecordset = adoCommand.Execute

      ' Enumerate the resulting recordset.

      strReturnVal = ""

      Do Until adoRecordset.EOF

          ' Retrieve values and display.    

          For intCount = LBound(arrProperties) To UBound(arrProperties)

                If strReturnVal = "" Then

                      strReturnVal = adoRecordset.Fields(intCount).Value

                Else

                      strReturnVal = strReturnVal & VbCrLf & adoRecordset.Fields(intCount).Value

                End If

          Next

          ' Move to the next record in the recordset.

          adoRecordset.MoveNext

      Loop
 

      ' Clean up.

      adoRecordset.Close

      adoConnection.Close

      Get_LDAP_User_Properties = strReturnVal
 

End Function

Open in new window

0

Join & Write a Comment

Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Know what services you can and cannot, should and should not combine on your server.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now