We do this with joined by PCs by having a powershell script run to join the PC to our Active Directory, then a VBS Script run to set the description to match the AD description. (NOTE: I changed all our info to SETME so you know which ones to modify.)
OPTION EXPLICIT
'==========================================================================
'
' NAME: Sync AD and Local Computer Description
'
'==========================================================================
'==========================================================================
' Declare Constants and Variables
'==========================================================================
Const STR_NET_BIOS_DOMAIN = "SETME"
Const STR_USER = "SETME"
Const STR_DOMAIN_USER = "SETME\SETME"
Const STR_PASSWORD = "SETME"
' Constants for the NameTranslate object and server-bind
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_SERVER_BIND = &H200
Const ADS_SECURE_AUTHENTICATION = &H1
' Decalare object variables
Dim objComputer, objDescrip, objNetwork, objADComputer
Dim ou, object, objComputerAD
Dim strComputer, strLDdescrip, strEmpty, strBlank
Dim strADPath, strComputerName, strADdescrip, strDescrip
Dim strDCserver
strComputer = "."
strBlank = ""
strEmpty = "EMPTY"
strDCserver = "SETME" 'like domain.com
'==========================================================================
' Pull and adjust local description
'==========================================================================
'Sets string "strLDdescrip" to local computer description
Set objComputer = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objDescrip = objComputer.ExecQuery("Select * FROM Win32_OperatingSystem")
For Each object In objDescrip
strLDdescrip = object.Description
Next
' Line below is for testing
'wscript.echo "Description before empty test = " & strLDdescrip
'Checks to see if local description is empty if so then put EMPTY into local description string
'If StrComp(strLDdescrip, strBlank, 1) = 0 OR IsNull (strLDdescrip) Then
strLDdescrip = "EMPTY"
'End If
' Line below is for testing
'wscript.echo "Local Description = " & strLDdescrip
'==========================================================================
' Connect into AD and get Full AD Path and Description from AD
'==========================================================================
'Get Full Computer Name
SET objNetwork = CREATEOBJECT("Wscript.Network")
strComputerName = objNetwork.ComputerName
ou = getOUByComputerName(strComputerName)
strADPath = "CN=" & strcomputername & "," & ou
'wscript.echo "Full AD Path = " & strADPath
Set objADComputer = GetObject("LDAP:")
Set objComputerAD = ObjADComputer.OpenDSObject("LDAP://" & strDCserver & "/" & strADPath, STR_DOMAIN_USER, STR_PASSWORD, _
ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
strADdescrip = objComputerAD.Description
'Checks to see if AD description is empty if so then put EMPTY into AD description string
'If StrComp(strADdescrip, strBlank, 1) = 0 Or IsNull (strADdescrip) Then
'strADdescrip = "EMPTY"
'End If
' Line below is for testing
'wscript.echo "AD Before = " & strADdescrip
'===========================================================================
' Conditional Testing for String Manipulation
'===========================================================================
' Check to see LD is empty AND AD is full, if so place AD into LD
' Lines below is for testing
'wscript.echo StrComp(strLDdescrip, strEmpty, 1)
'wscript.echo StrComp(strADdescrip, strEmpty, 1)
'If StrComp(strLDdescrip, strEmpty, 1) = 0 And StrComp(strADdescrip, strEmpty, 1) = -1 Then
' Line below is for testing
'wscript.echo "LD is Empty and AD is Full -1, placing AD into LD"
For Each object In objDescrip
object.Description = strADdescrip
object.put_
' Line below is for testing
'wscript.echo "LD now has " & object.Description
Next
'Elseif StrComp(strLDdescrip, strEmpty, 1) = 0 And StrComp(strADdescrip, strEmpty, 1) = 1 Then
' Line below is for testing
'wscript.echo "LD is Empty and AD is Full 1, placing AD into LD"
For Each object In objDescrip
object.Description = strADdescrip
object.put_
' Line below is for testing
'wscript.echo "LD now has " & object.Description
Next
'Else
' Line below is for testing
'wscript.echo "LD is Full so Placing LD into AD no matter what"
'objComputerAD.Description = strLDdescrip
'objComputerAD.SetInfo
' Line below is for testing
'wscript.echo "Ad now has " & objComputerAD.Description
'End If
' Line below is for testing
'wscript.echo "Script Is Done"
function getOUByComputerName(byval strcomputerName)
' *** Function to find ou/container of computer object from computer name ***
Dim objTrans, strComputerDN
' Retrieve NetBIOS name of local computer.
' Use NameTranslate to convert NT form of computer name into DN.
Set objTrans = CreateObject("NameTranslate")
' Initialize by locating Global Catalog. Specify credentials.
objTrans.InitEx ADS_NAME_INITTYPE_GC, "", STR_USER, STR_NET_BIOS_DOMAIN, STR_PASSWORD
' Use the Set method to specify the NT format of the name.
objTrans.Set ADS_NAME_TYPE_NT4, STR_NET_BIOS_DOMAIN & "\" & strComputerName & "$"
' Use the Get method to retrieve the DN.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
ou = mid(strComputerDN,instr(strComputerDN,",")+1,len(strComputerDN)-instr(strComputerDN,","))
getOUByComputerName = ou
End Function
An alternative idea may be to create a small CSV database file MAC ADDRESS , DESC and a small VBS that :
1-determines the MAC addess
2-lookup in the database file is there is a match
3-set the description
This can be a post-install task.
Regards,
Marco - StockTrader 10 years ago