Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-04
3
Medium Priority
?
1,058 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

715 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