In the second part of a three-part series, Chris Wolf looks at querying Active Directory to determine virtual machine...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
location based on computer object description attributes.
In part one of this series, I covered a technique for leveraging the virtual machine properties to differentiate between physical and virtual servers and identify virtual machine location. I also explained how to use a vbscript to modify the computer object Description attribute for a large number of computers.
In this article, I'm going to cover a method for querying Active Directory to find computer objects that match a pre-determined Description attribute prefix, and in turn help detect the virtual machine location. For example, if you want to find the virtual machine location for all computers, you would need to find all computers whose Description attribute started with "V." To find a Xen-based virtual machine location, querying Active Directory with my script would look for computers whose Description attribute started with "Vxen."
While in my last article I explained how to use Active Directory Users and Computers to perform computer object searches, sometimes you may find that you want the output stored in a text file for integration with other management tools or for long term record keeping. With that in mind, the script QueryDescription.vbs, available from my site as a text download, can be used for querying Active Directory, which returns a list of computers whose Description attribute starts with a pre-determined string.
To use the script for querying Active Directory in your environment, there are three variables that you will need to edit:
strPrefix identifies the Description attribute prefix to include in the search. For example, setting strPrefix to "V" will return a list of all VMs. If strPrefix was set to "Ps," a list of all physical servers would be returned after querying Active Directory.
strDomainTarget is used to specify the distinguished name of the domain that you wish to query, and should be set to match your domain name. So if you managed the searchservervirtualization.com domain, strDomainTarget would need to be set to "dc=searchservervirtualization,dc=com." Note that you could also limit the scope of the connection to a single OU by adding to the distinguished name. For example, to connect to the "Web" OU in the TechTarget.net domain, strDomainTarget would need to be set to "ou=web,dc=techtarget,dc=net."
The last variable that may require modification when querying Active Directory is strLogFile. strLogFile identifies the location of where the script's output log file will be stored. By default, it is set to save to the root directory of the C drive. Here is a sample of what the resultant log file will display:
The following computers have the vesx Description Prefix:
Computer Name ============= FS1 FS2 Hernandez Maine web1 web2 web3
As you can see, identifying virtual machine location by querying Active Directory isn't as hard as it looks. Using scripts to modify the Description attribute to identify computers as specific VM types or as physical systems can allow you to quickly put a system in place to more easily track virtual machine location across your enterprise. Once all existing physical and virtual computer objects are set with the appropriate prefix in their description attribute, querying Active Directory simply requires that all new computers added to the domain have the correct Description attribute prefix as well (Vesx, Vvi, Vms, etc.). You organization's deployment and change control processes will likely need to be updated to ensure that this occurs.
In the last part of this series, I explore methods for customizing Active Directory in order to make use of custom virtual machine attributes. If making use of the existing Description attribute is not for you, then hopefully the solution documented in the next article will provide just what you need.
About the author
Chris Wolf is a Microsoft MVP for Windows Server – File System/Storage and is a MCSE, MCT, and CCNA. He's a Senior Analyst for Burton Group who specializes in the areas of virtualization solutions, high availability, enterprise storage, and network infrastructure management.
Dig Deeper on Virtual machine monitoring, troubleshooting and alerting