Notification

Icon
Error

Setting Computer AD Description Attribute

Posted: Friday, May 16, 2014 12:10:56 AM(UTC)
keys_it

keys_it

Member Original PosterPosts: 31
0
Like
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 name. Then it prompts for the new description and if it is not blank then it will set it in AD.

Here is the vbscript code:

Code:

' Get computer object in AD
strComputer = WScript.Arguments(0)

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=com' WHERE objectCategory='computer' and name = '" & strComputer & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
     strDN = objRecordSet.Fields("distinguishedName").Value
     objRecordSet.MoveNext
Loop

Set objComputer = GetObject("LDAP://" & strDN)

' Input new AD computer description field
newDescription = InputBox("Please enter the new AD Computer Description: ", "New description")
If newDescription = "" Then
	Wscript.Echo ("Invalid description and this script will quit.")
	Wscript.Quit
End If

' Write to AD computer object	
objComputer.Put "Description" , newDescription
objComputer.SetInfo


Save the code as changeCompDesc.vbs and save it into your action folder on the Lansweeper server.
Remember to change the domain in line 15 to your own domain.
Lansweeper
#1Lansweeper Member Posts: 13,442  
posted: 5/16/2014 10:19:09 PM(UTC)
Thanks for posting!
jacobsenm
#2jacobsenm Member Posts: 63  
posted: 5/19/2014 5:29:34 PM(UTC)
I was waiting for this one very long.
Good post ! Thank you,
DJSMC
#3DJSMC Member Posts: 3  
posted: 10/4/2020 4:46:17 PM(UTC)
Is anyone else having issue with this action?

I am getting a error:

Windows Script Host
Line: 18
Char: 1
Error: Either BOF or EOF is True, or the current record has been deleted. Requestd operation requires current record.
Code: 800A0BCD
Source: ADODB.RecordSet
DJSMC
#4DJSMC Member Posts: 3  
posted: 10/27/2020 12:39:54 PM(UTC)
Okay well I figure this out finally. It seems that a possible update to LS was causing it to send a FQDN for the computer to the variable in the script, so using regular expressions I was able to strip out our .xxxx.edu ending so the sql query would work.


See below and be sure to replace line 5 code for to match your domain for the RegX.Pattern as well as in line 23. Notice I actually made a call to a specific DC as we have multiple and this seems to speed things up a bit.


' Get computer object in AD
strCompFQDN = WScript.Arguments(0)
Dim RegX
Set RegX = NEW RegExp
RegX.Pattern = ".xxxxx.edu"
RegX.Global = True
strComputer = RegX.Replace(strCompFQDN, "")

' MsgBox strCompFQDN
' MsgBox strComputer

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://DC1.xxxx.edu/DC=xxxx,DC=edu' WHERE objectCategory='computer' and name = '" & strComputer & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Loop

Set objComputer = GetObject("LDAP://" & strDN)

' Input new AD computer description field
newDescription = InputBox("Please enter the new AD Computer Description: ", "New description")
If newDescription = "" Then
Wscript.Echo ("Invalid description and this script will quit.")
Wscript.Quit
End If

' Write to AD computer object
objComputer.Put "Description" , newDescription
objComputer.SetInfo

Active Discussions

Lansweeper Software deployment initiated by user
by  LS_enthusiast_4444  
Go to last post Go to first unread
Last post: Yesterday at 9:28:18 PM(UTC)
Lansweeper Help Desk not disabling for regular users?
by  FrankSc   Go to last post Go to first unread
Last post: Yesterday at 8:18:38 PM(UTC)
Lansweeper Satisfaction Questionnaire after ticket close
by  mouaad  
Go to last post Go to first unread
Last post: Yesterday at 4:31:44 PM(UTC)
Lansweeper Microsoft EDGE browser support
by  Vapoured   Go to last post Go to first unread
Last post: Yesterday at 4:54:30 AM(UTC)
Lansweeper Asset Management - Unattached assets
by  MrDiamond  
Go to last post Go to first unread
Last post: 11/25/2020 8:15:16 PM(UTC)
Lansweeper Lansweeper Fresh Install Hanging, High CPU, Unusable
by  ebars   Go to last post Go to first unread
Last post: 11/24/2020 7:53:38 PM(UTC)
Lansweeper Forwarding tickets to regular email recipents
by  ChristerT  
Go to last post Go to first unread
Last post: 11/24/2020 9:48:15 AM(UTC)