Read from an Active Directory computer object attribute (VBS)

Purpose: You have information that you need to read from an AD object attribute

Now that you have an attribute full of exiting new information, you need to get it down for business! From SCCM point of view – this usually is an AD computer object attribute (which value could be, for example, the physical location of the computer or the year the computer has been purchased, etc.). Yes well im glad if you also had read my previous article “Write to an Active Directory computer object attribute (VBS). You should know then that I really did not bother to come up with anything original to this description, its just a copy paste! But the script below really does what the topic claims it to do. With the script you can read the attribute value and continue your adventure with it anyway you want!

Usage: cscript.exe IT_OSD_VBS_ReadComputerADAttribute.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 read.

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
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_ReadFromComputerObjectAttribute
' ** 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_ReadFromComputerObjectAttribute (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"
    DebugMode = "Yes"
 
' *****************************************************************************
' *** Script Information Reading Actions **************************************
' *****************************************************************************
'Where the computer is now, we need a location to change the attributes...
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
    objAttribute = eval("objComputer" + "." + SelectYourAttribute)
 
    if DebugMode = "Yes" Then
        MsgBox("Your Attribute=" + "objComputer" + "." + SelectYourAttribute)
        MsgBox("Change AD attribute for current workstation (" & objSysInfo.ComputerName & "), Attribute current value: (" & objAttribute & ")")
        MsgBox("Script has reached its end.")
    End If
 
    return objAttribute
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_ReadFromComputerObjectAttribute
' ** 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_ReadFromComputerObjectAttribute (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"
	DebugMode = "Yes"

' *****************************************************************************
' *** Script Information Reading Actions **************************************
' *****************************************************************************
'Where the computer is now, we need a location to change the attributes...
	Set objSysInfo = CreateObject("ADSystemInfo")
	Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
	objAttribute = eval("objComputer" + "." + SelectYourAttribute)

	if DebugMode = "Yes" Then
		MsgBox("Your Attribute=" + "objComputer" + "." + SelectYourAttribute)
		MsgBox("Change AD attribute for current workstation (" & objSysInfo.ComputerName & "), Attribute current value: (" & objAttribute & ")")
		MsgBox("Script has reached its end.")
	End If

	return objAttribute

Leave a Reply

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


+ nine = ten

Post Navigation