Computer Description Active Directory Vbscript

Setting Computer AD Description Attribute: I wanted to share a custom action that I created that has helped me tremendously. This custom action will change the AD Description for what ever computer asset your on. It calls on a vbscript file called changeADCompDesc.vbs and passes the computer.

Get computer description using ADO Active Directory

Get computer description using ADO Active Directory

I am having a really hard time getting the computer description from an Active Directory computer account to work. I understand that ADO retruns an array for the description so I took that into account when I created my script. I am having a problem on line 43 of my script which is this line
arrDesc = objRecordSet.Fields('description').Value
The error I receive is
ADODB.Fields: Item cannot be found in the collection corresponding to the requested name or ordinal.
I used ADSI edit and description is a valid field for a computer object.
PLEASE PLEASE PLEASE Help me or Shoot me :)
'On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
dim objShell
dim objScriptExec
dim strPingResults
dim fso
dim CSVFile
dim strFileName
strFileName = 'C:tempLogged-On-Users.csv'
Set objShell = CreateObject('WScript.Shell')
Set fso = CreateObject('Scripting.FileSystemObject')
If fso.FileExists(strFileName) Then
'File is present so delete it
fso.DeleteFile(strFileName)
Wscript.Echo 'Creating File: ' & strFileName
Set CSVFile = fso.CreateTextFile(strFileName, True)
Else
Wscript.Echo 'Creating File: ' & strFileName
Set CSVFile = fso.CreateTextFile(strFileName, True)
End If
Set objConnection = CreateObject('ADODB.Connection')
Set objCommand = CreateObject('ADODB.Command')
objConnection.Provider = 'ADsDSOObject'
objConnection.Open 'Active Directory Provider'
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = 'Select Name, Location from 'LDAP://OU=Computers,OU=Michigan Administrative Information Systems (MA), DC=bf,DC=umich,DC=edu' ' & 'Where objectClass='computer'
objCommand.Properties('Page Size') = 1000 'make this larger if there is more then 1000 computers in AD
objCommand.Properties('Searchscope') = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
dim strMember
dim arrDesc
Do Until objRecordSet.EOF
Wscript.Echo 'Computer Name: ' & objRecordSet.Fields('Name').Value
arrDesc = objRecordSet.Fields('description').Value
if isArray(objRecordSet.Fields('description')) then
wscript.echo 'It's an array'
for each strMember in arrDesc
wscript.echo strMember
Next
else
wscript.echo 'No'
end if
strComputer = objRecordSet.Fields('Name').Value
Set objScriptExec = objShell.Exec('ping -n 2 -w 1000 ' & strComputer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, 'reply from') Then
wscript.echo 'Machine: ' & strComputer & ' responded to ping.'
Set objWMIService = GetObject('winmgmts:'&'{impersonationLevel=impersonate}!' & strComputer & 'rootcimv2')
Set colComputer = objWMIService.ExecQuery('Select * from Win32_ComputerSystem')
For Each objComputer in colComputer
Wscript.Echo strComputer
Wscript.Echo 'User: ' & objComputer.UserName
CSVFile.WriteLine (strComputer & ',' & objComputer.UserName)
Next
wscript.echo '
wcript.echo '
Else
'the machine did not respond to ping. Mark the machine as offline in the CSV file
CSVFile.WriteLine (strComputer & ',' & 'Offline')
wscript.echo 'Machine: ' & strComputer & ' is currently offline.'
wscript.echo '
wcript.echo '
End If
objRecordSet.MoveNext 'Move to the next record
Loop
CSVFile.Close 'Close the CSV file
Posted by1 year ago
Archived

Hi,

I would like to populate the description field on all cmputer objects with the username of the person logged as well as some other info.

Active Directory Tools

I have found two scripts but just wanted to know the differences in them:

The first script i found was this one, it works really well

But then i was looking at another one very similar and some people were saying that if you do it after every logon, you can quickly exhaust the USN for the whole AD domain.

Directory

Microsoft Active Directory

To counter this apparently the script below will only write new info in the description field when something changes (such as a different user logging onto the machine)

I dont want to be in a situation where i mess up my domain, so i am asking here if the second script looks ok to you guys?

24 comments