Script to Update computer's dscription in AD with Description set on local computer using GPO.

Posted on 2008-10-04
Last Modified: 2008-11-06
Our school district is wanting to redo all of our computer naming standards and are wanting to use the Description Field on the remote computer but we have found they do not update or sync with Active Directory and we want this to be updated regularly using a startup script or logon script.  I have found a Script to update the description to show who was logoned on and at what time. But I am not a programer and cant find a way to pull the description and update that to active directory using the same script.

Here is some code to update the description to show the user who is loged on, is there a way of modifying this for my needs.
---A sample batch script.---------------------------

@echo off


for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr IP.*Address\.') do set ipAddr=%%a&goto :FOUNDIP

echo Couldn't find IP

goto :EOF


set Machine=%computername%

set Description=%USERNAME% %ipAddr% %date%

for /f "delims=" %%a in ('dsquery computer -name "%Machine%"') do set MachineDN=%%a

dsmod computer %MachineDN% -desc "Logged in User: %Description%"

---Sameple VB Script.------------------------------

Set objSysInfo = CreateObject("ADSystemInfo")


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

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


strMessage = objUser.CN & " logged in at " & objComputer.CN & " " & Now & "."


'objUser.Description = strMessage



objComputer.Description = strMessage


Open in new window

Question by:MightyElectro
  • 2
LVL 31

Expert Comment

by:Henrik Johansson
ID: 22641422
Not clear what you want to.
Do you wnat to rename the computername based on description or update the description field based on computername?

Author Comment

ID: 22641721
Hi henjoh09     Im not wanting to do either,  what we have is a naming standard where we have our trt's or technology resource teachers update all the names of each computer to    ComputerName =(location - %servicetag% )  and then in the description we are having them put in the ( location - room# - computer# - assettag# etc) but after doing this we have found the description doesnt update and sync to AD so I was hoping to find a script or modify a script to pull the description the TRT had entered in on the local machine and have that synced up to AD automatically eitehr on startup or when a user logson.

Accepted Solution

MightyElectro earned 0 total points
ID: 22858394
I have found a script I can run on my workstation and can schedule as a task.

Here is the code for anyone else who is having trouble with this.
On Error Resume next


	strSourceOU = "CN=Computers,DC=Your,DC=domain,DC=net"

	strLDAP = "(&(sAMAccountType=805306369)(objectCategory=computer))"


	set oRootDSE = GetObject("LDAP://RootDSE")

	strDomainNC = oRootDSE.Get("defaultNamingContext")

	set oRootDSE = Nothing


	Set oConnection   = CreateObject("ADODB.Connection")

	oConnection.Provider   = "ADsDSOObject"

	oConnection.Open "Active Directory Provider"


	Set oCommand = CreateObject("ADODB.Command")

	Set oCommand.ActiveConnection = oConnection


	strQuery = "<LDAP://"& strSourceOU &">;" & strLDAP & ";AdsPath;subTree"


	oCommand.CommandText = strQuery   

	oCommand.Properties("Page Size") = 1000


	Set oRecordSet = oCommand.Execute


	if not oRecordSet.Eof Then

		WScript.Echo "- Object Count: " & oRecordSet.RecordCount

		While Not oRecordSet.Eof

			Set x = GetObject(oRecordSet.Fields("AdsPath").Value)

			WScript.Echo "Before: " & & " - " & x.description

			x.description = GetLocalDesc(Replace(,"CN=",""))


			WScript.Echo "After:  " & & " - " & x.description



	end If

	WScript.Echo "done..."


Function GetLocalDesc(strComputer)

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

	Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

	For Each objitem In colitems

		GetLocalDesc =  objitem.description


End Function

Open in new window


Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
Synchronize a new Active Directory domain with an existing Office 365 tenant
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

758 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