' =================================================================== ' Author: Ivan Dretvic ' ivan@dretvic.com ' DATE CREATED: 08/10/2012 ' ' Documentation: http://ivan.dretvic.com/2012/10/automatically-generate ' -description-field-for-computers-in-active-directory/ ' ' This script is designed to assist System Administrators by populating ' description field of Active Directory Computers. The sript can run ' at log-on and log-off, and is executed by the user. You need to set ' appropriate permissions on Active Directory for Authenticated Users ' to have write access to the description field. Refer to documentation ' for more information. ' =================================================================== 'On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) Set objUser = GetObject("LDAP://" & objSysInfo.UserName) If left(objComputer.description,1) = "`" Then 'If a tilda exists the script will terminate. This allows custom ' descriptions that dont get overwritten. Wscript.Quit Else 'Sets variables for Computer name, Manufacturer, Model, ' and Serial number strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputerSystem = objWMIService.ExecQuery ("Select * from Win32_computersystem") Set colBIOS = objWMIService.ExecQuery ("Select * from Win32_BIOS") For each objComputerSystem in colComputerSystem GetComputerManufacturer = objComputerSystem.Manufacturer GetComputerModel = objComputerSystem.Model Next For each objBIOS in colBIOS GetSerialNumber = objBIOS.SerialNumber Next 'String cleaning - Manufacturer includes only first word, and ' the serial removes any spaces. txtCount = InStr(GetComputerManufacturer," ") - 1 GetComputerManufacturer = Left(GetComputerManufacturer,txtCount) GetSerialNumber = Replace(GetSerialNumber, " ", "") 'Below are two variants in building the final string. Please chose which ' you prefer. I did read but could not validate that excessive computer description ' changes can cause AD change limits to be reached. 'First one is without dates and second is with dates. Below ar examples. The ' string is also trimmed to 1024 characters as per AD schema req (just in case) '### DESCRIPTION WITHOUT DATE ### 'Example: 'John Doe (jdoe) - Dell Optiplex 990 - DRP421S strCompDesc = objUser.SAMAccountName & " | " & objUser.CN & " | " & GetComputerManufacturer & " " & GetComputerModel & " | " & GetSerialNumber strCompDesc = Left(strCompDesc,1024) 'Compares AD string and generated string and skips if they are ' identical. This saves AD change count. If strCompDesc = objComputer.description Then wscript.Quit Else objComputer.Description = strCompDesc objComputer.SetInfo End If ' '### DESCRIPTION WITH DATE ### ' 'Example: ' '2012/11/23 - John Doe (jdoe) - Dell Optiplex 990 - DRP421S ' strDate = Year(Date) & "/" & Month(Date) & "/" & Day(Date) & " | " ' strCompDesc = strDate & objUser.SAMAccountName & " | " & objUser.CN & " | " & GetComputerManufacturer & " " & GetComputerModel & " | " & GetSerialNumber ' strCompDesc = Left(strCompDesc,1024) ' objComputer.Description = strCompDesc ' objComputer.SetInfo End If