Solved

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

Posted on 2008-10-04
3
1,036 Views
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
 
setlocal
 
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr IP.*Address\.') do set ipAddr=%%a&goto :FOUNDIP
 
echo Couldn't find IP
goto :EOF
 
:FOUNDIP
 
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
'objUser.SetInfo
 
objComputer.Description = strMessage
objComputer.SetInfo

Open in new window

0
Comment
Question by:MightyElectro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
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?
0
 

Author Comment

by:MightyElectro
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.
0
 

Accepted Solution

by:
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.name & " - " & x.description
			x.description = GetLocalDesc(Replace(x.name,"CN=",""))
			x.setinfo 
			WScript.Echo "After:  " & x.name & " - " & x.description
			oRecordSet.MoveNext		
		Wend
	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
	Next
End Function

Open in new window

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

623 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