Write to an Active Directory computer object attribute (VBS)

Purpose: You have information that you need to write to an AD objects attribute

Fancy stuff: you are in a dire need to automate AD object attribute writing. Usually (from SCCM point of view) this object is a computer object, and the attribute contains some additional information about the computer that your corporation has requested. This additional information could be, for example, the physical location of the computer or some specific owner details. The script below allows you to write to the current computer AD object (because it is used usually in a task sequence). Happy writing!

Usage: cscript.exe IT_OSD_VBS_WriteToComputerObjectAttribute.vbs (no parameters exist)
Debugging: You can uncomment the msgbox rows, to see what values you are receiving.
Configuration: You need to change the AD Attribute that you want to write to

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_WriteToComputerObjectAttribute
' ** Created on: 24.10.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: You have information that you need to write to an AD object Attribute
' ** Usage: IT_OSD_VBS_WriteToComputerObjectAttribute.vbs (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 24.10.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 03.05.2013 / Created better configuration options.
' *********************************************************************************
 
 On Error Resume Next
 
' *****************************************************************************
' *** Configure Script ********************************************************
' ***************************************************************************** 
    SelectYourAttribute = "extensionAttribute1"
    WriteToYourAttribute= "Hello World!"
    DebugMode = "No"
 
' *****************************************************************************
' *** Script Information Writing Actions **************************************
' *****************************************************************************
'Where the computer is now, we need a location to change the attributes...
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
    
    if DebugMode = "Yes" Then
        MsgBox ("Your Attribute=" + "objComputer" + "." + SelectYourAttribute)
        objAttribute = eval("objComputer" + "." + SelectYourAttribute)
        MsgBox("Change AD attribute for current workstation (" & objSysInfo.ComputerName & "), Attribute old value: (" & objAttribute & "), Attribute new value: (" & WriteToYourAttribute & ")")
    End If
        
        objComputer.Put SelectYourAttribute, WriteToYourAttribute
        objComputer.SetInfo
    
    if DebugMode = "Yes" Then   
        MsgBox("Script has reached its end.")
    End If
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_WriteToComputerObjectAttribute
' ** Created on: 24.10.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: You have information that you need to write to an AD object Attribute
' ** Usage: IT_OSD_VBS_WriteToComputerObjectAttribute.vbs (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 24.10.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 03.05.2013 / Created better configuration options.
' *********************************************************************************

 On Error Resume Next
 
' *****************************************************************************
' *** Configure Script ********************************************************
' *****************************************************************************	
	SelectYourAttribute = "extensionAttribute1"
	WriteToYourAttribute= "Hello World!"
	DebugMode = "No"
 
' *****************************************************************************
' *** Script Information Writing Actions **************************************
' *****************************************************************************
'Where the computer is now, we need a location to change the attributes...
	Set objSysInfo = CreateObject("ADSystemInfo")
	Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
	
	if DebugMode = "Yes" Then
		MsgBox ("Your Attribute=" + "objComputer" + "." + SelectYourAttribute)
		objAttribute = eval("objComputer" + "." + SelectYourAttribute)
		MsgBox("Change AD attribute for current workstation (" & objSysInfo.ComputerName & "), Attribute old value: (" & objAttribute & "), Attribute new value: (" & WriteToYourAttribute & ")")
	End If
		
		objComputer.Put SelectYourAttribute, WriteToYourAttribute
		objComputer.SetInfo
	
	if DebugMode = "Yes" Then	
		MsgBox("Script has reached its end.")
	End If

Leave a Reply

Your email address will not be published. Required fields are marked *


seven − six =

Post Navigation