Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
By retrieving and reviewing computer account attributes you can do such things as identify the computers owned by each department, or compile a list of the computers that are located in a particular location (city, building, floor, room). This information is very useful in a number of situations, from planning new equipment allocations to making preparations to move a group of users from one building to another.
You can use the ADSI IADs Get method to retrieve the attributes of any computer account in Active Directory. You simply bind to the appropriate computer account and then echo the value of the desired attributes.
Creating a script to return computer account attributes is easy, but there is one caveat you must be aware of. Although you can retrieve any attribute by using ADSI, a problem can occur if any of these attributes have a null value (that is, if no value has been assigned to the attribute). For example, suppose you create a computer account and assign values only to the mandatory attributes. In that instance, all the optional attributes, including such properties as Location and Description, will have a null value, which means no value has been assigned to the attribute.
Although a script can retrieve attributes with null values, an error will occur if you attempt to do things such as assign that value to a variable or echo the value to the screen. For example, if you attempt to report the value, you will receive the following error message:
The property could not be found in the cache.
To avoid getting this error, your script must do two things:
You can check for null values by using the function IsNull in Microsoft® Visual Basic® Scripting Edition (VBScript). The following code sample tests to see if the value assigned to the variable strLocation is null. If it is, a message is echoed.
If IsNull(strLocation) Then Wscript.Echo
"The location has not been configured for this computer.
"Else Wscript.Echo
"Location:
"& strLocation End If
Listing 9.5 contains a script that enumerates the values of two attributes of a computer account. To carry out this task, the script must perform the following steps:
This same approach can be used to retrieve additional computer account attributes.
Listing 9.5 Enumerating Computer Account Attributes
|
|
Send us your feedback | « Previous | Next » |