Results 1 to 8 of 8

Thread: Sync AD computer description field with local computer description field.

  1. #1
    Michael Guest

    Sync AD computer description field with local computer description field.

    Hello

    Is there a way to sync the computer description field in AD with the
    computer description field on the my computer properties computername tab.

    FROM: XP PRO ( Local computer description field) >>>>>>>>> TO: SRV 2003
    (AD computer description field)

    We are doing a role out of a couple thousand computers and would like the
    local computer techs to fill out workstation description field and have it
    populate the AD computer description field.


    Thanks in advance for any help.



  2. #2
    Jeremy Guest

    Re: Sync AD computer description field with local computer description field.

    I'm sure you could do this via a combination WMI/ADSI script. But you'd
    have to run it AFTER the rollout, ensuring all the compters were swtiched
    on, then run the script against a list of computer names that:

    Connects to the remote computer and determines the description
    Writes the description to the computer object

    I'd do this with a short vbscript that accepts then computer name as an
    argument and just does that computer. Then I'd do a batch file loop that
    loops through a text file with each different computer name in the file
    passing it to the vbscript.

    I can see from setting my computer description to "dishwasher" and then
    searching the registry for dishwasher, that the value is stored in:
    "HKLM\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters\srvcomment"

    So here is a link to a script to retireve a registry value with vbscript:
    http://www.microsoft.com/technet/scr....mspx?mfr=true

    And here is a link to a script to write to the Location property of a
    computer account, replace "Location" with "Description":
    http://www.microsoft.com/technet/scr....mspx?mfr=true

  3. #3
    Join Date
    Jan 2008
    Posts
    10

    Re: Sync AD computer description field with local computer description field.

    Is there a way (script) to find the current logged on user and query Active Directory for the user's first name and last name and then update the description field?

  4. #4
    Richard Mueller [MVP] Guest

    Re: Sync AD computer description field with local computer description field.

    Active Directory is not designed to store short-lived, frequently updated
    information like that. Active Directory has no information about which user
    is logged into which computer.

    If in your environment you have a fixed relationship between users and
    computers, you could create a text file of user Distinguished Names and
    computer Distinguished Names. Then you could code a one time script to
    populate the user description field with the information you want. If you
    have many users you could start with a logon script that logs the user and
    computer names to a shared text file.

  5. #5
    Richard Mueller [MVP] Guest

    Re: Sync AD computer description field with local computer description field.

    To get you started on a one-time scripting solution, here is an example
    VBScript program that creates a text file with the Distinguished Names of
    all users in the domain:

    http://www.rlmueller.net/Create%20User%20List%202.htm

    The same program can be modified to document all computer objects in the
    domain. Just modify this filter:

    ' Filter on all users.
    strFilter = "(&(objectCategory=person)(objectClass=user))"

    so it looks like this:

    ' Filter on all computers.
    strFilter = "(objectCategory=computer)"

    The program requires the name of the text file to be created, passed as a
    parameter to the program. There will be one Distinguished Name per line in
    the file created. You can read both files into a spreadsheet program and
    juggle it around until you line up the computers with the users. Note the
    file of computers will include servers and Domain Controllers, so delete
    those. You should end up with a spreadsheet where the first column is the
    Distinguished Name of users, and the second column is the Distinguished Name
    of the associated computer. Then you can use this spreadsheet as the input
    for another script to populate the description field of users. Such a
    program could look like below:
    =======
    Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strComputerDN
    Dim objUser, objComputer, strNetBIOSName

    ' Check for required arguments.
    If (Wscript.Arguments.Count < 1) Then
    Wscript.Echo "Arguments <FileName> required. For example:" & vbCrLf _
    & "cscript UserDescription.vbs c:\Scripts\UserList.xls"
    Wscript.Quit
    End If

    ' Spreadsheet file.
    strExcelPath = Wscript.Arguments(0)

    ' Bind to Excel object.
    On Error Resume Next
    Set objExcel = CreateObject("Excel.Application")
    If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
    End If
    On Error GoTo 0

    ' Open spreadsheet.
    On Error Resume Next
    objExcel.Workbooks.Open strExcelPath
    If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Spreadsheet cannot be opened: " & strExcelPath
    Wscript.Quit
    End If
    On Error GoTo 0

    ' Bind to worksheet.
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

    ' Read each row of spreadsheet until a blank is found in the first column.
    ' The first column is the DN of a user.
    ' The second column is the DN of a corresponding computer.
    ' intRow is the row number of the spreadsheet.
    intRow = 1
    Do While objSheet.Cells(intRow, 1).Value <> ""
    strUserDN = objSheet.Cells(intRow, 1).Value
    strComputerDN = objSheet.Cells(intRow, 2).Value
    On Error Resume Next
    Set objUser = GetObject("LDAP://" & strUserDN)
    If (Err.Number = 0) Then
    Set objComputer = GetObject("LDAP://" & strComputerDN)
    If (Err.Number = 0) Then
    On Error GoTo 0
    ' Assign the NetBIOS name of the computer to the description
    ' attribute of the user.
    strNetBIOSName = objComputer.sAMAccountName
    ' Strip off trailing "$" character.
    strNetBIOSName = Left(strNetBIOSName, Len(strNetBIOSName) - 1)
    objUser.description = strNetBIOSName
    ' Save change.
    objUser.SetInfo
    Else
    On Error GoTo 0
    Wscript.Echo "Computer " & strComuterDN & " not found"
    End If
    Else
    Wscript.Echo "User " & strUserDN & " not found"
    On Error GoTo 0
    End If
    intRow = intRow + 1
    Loop

    ' Close the workbook.
    objExcel.ActiveWorkbook.Close

    ' Quit Excel.
    objExcel.Application.Quit

    Wscript.Echo "Done"
    ============
    I decided to assign the NetBIOS name of the computer to the description
    field. You might want to user the Distinguished Name instead, in which case
    there is no need to bind to the computer object.

    --

  6. #6
    Al Dunbar Guest

    Re: Sync AD computer description field with local computer description field.

    I agree with Richard that AD is not the best place to keep that type of
    information. Add to that the fact that the script would need to be run by an
    account with sufficient privileges to modify the computer account's
    description field. Also add to this the fact that this information would not
    indicate who is currently logged on, but who last logged on.

  7. #7
    Join Date
    Sep 2011
    Posts
    1

    Re: Sync AD computer description field with local computer description field.

    Here is a script I wiped up to set the description field for both the local and domain computers. It set this to the user names that has logged into the workstation. (look out for the text warping!)

    'This script will set the local and domain Description fields to the username of the logged on user

    const HKEY_LOCAL_MACHINE = &H80000002
    Const constComputer = "."
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & constComputer & "\root\default:StdRegProv")

    'Geting LDAP Information about User and Computer
    Set objRootDSE = GetObject("LDAP://RootDSE")
    Set objADSysInfo = CreateObject("ADSystemInfo")
    strUserDN = objADSysInfo.username
    strComputerName = objADSysInfo.ComputerName
    Set objUser = Getobject("LDAP://" & strUserDN)

    'Setting the Users Name in the Description of Local Host
    strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
    objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, "srvcomment", objUser.Get("givenName") & " " & objUser.Get("sn")

    'WScript.Echo "Name " objUser.Get("givenName") & " " & objUser.Get("sn") & "Computer Name: " & strComputerName

    'Setting the Users Name in the Description Filed for AD
    Set objComputer = GetObject("LDAP://" & objADSysInfo.ComputerName)
    objComputer.PutEx 2, "description", Array (objUser.Get("givenName") & " " & objUser.Get("sn"))
    objComputer.SetInfo

  8. #8
    Join Date
    Oct 2011
    Posts
    1

    Re: Sync AD computer description field with local computer description field.

    Here is what I came up with from a mash up of multiple vbscripts I came across

    I added this as a Immediate Scheduled task in a server 2008 AD system

    ========================================================
    Dim strComputer
    Dim Descrip
    Dim strDescrip
    Dim strEmpty
    strComputer = "."
    strEmpty = ""

    'Sets string "strDescrip" to local computer description
    Set Obj = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set Descrip = Obj.ExecQuery("Select * FROM Win32_OperatingSystem")
    For Each object In Descrip
    strDescrip = object.Description
    Next

    'Checks to see if local description is empty if so then exits
    If StrComp(strDescrip, strEmpty, 1) = 0 Then
    Wscript.Quit
    End if

    'Comment back in for testing of string
    'wscript.echo "Local Description = " & strDescrip

    'Connects into AD
    Set objSysInfo = CreateObject("ADSystemInfo")

    Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
    Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)

    'Comment back in for testing of string
    'wscript.echo "AD Before = " & objComputer.Description

    'Sets AD description to same as local description as long as AD is empty
    if StrComp(objComputer.Description, strEmpty, 1) = 0 Then
    objComputer.Description = strDescrip
    objComputer.SetInfo
    End If

    'Comment back in for testing of string
    'wscript.echo "AD After = " & objComputer.Description

    ========================================================

Similar Threads

  1. Remove description field of all bookmarks in Firefox
    By Nalak in forum Technology & Internet
    Replies: 3
    Last Post: 11-06-2012, 01:35 PM
  2. Replies: 1
    Last Post: 10-01-2012, 12:23 PM
  3. Replies: 5
    Last Post: 24-12-2010, 02:07 PM
  4. Multi Field value field in Microsoft Access
    By Erubiel in forum Windows Software
    Replies: 3
    Last Post: 20-11-2009, 12:55 AM
  5. Use the "Managed By" field in AD to set as local Admin
    By ErikW in forum Active Directory
    Replies: 4
    Last Post: 14-05-2009, 02:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,629,107.97516 seconds with 17 queries