Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Retrieving Information from Computers Belonging to an Active Directory OU

This script queries a particular Organizational Unit (OU) in your Active Directory for a list of computers. It will then use WMI to query various properties of those computers and output it into table format. Take a look at the script Listing 3-2.

$ou = [ADSI]"LDAP://ou=test,dc=testlab,dc=local"
$computers = $ou.PSBase.Get_Children()
$arrInfo = @()
foreach($node in $computers){
$arrInfo += Get-WmiObject - query "Select `
	Name,Manufacturer,Model, `
	NumberOf Processors, `
	TotalPhysicalMemory `
	From Win32_ComputerSystem" `
	-computername &node.Name
}
$arrInfo | format-table Name,Manufacturer, `
	Model, NumberOf Processors, TotalPhysicalMemory

Listing 3-2

As you can see in Figure 3-2, this script lists the name, manufacturer, model, number of processors, and the total amount of physical memory for each computer in the given OU. For now, I'm assuming that every item in the given OU is a computer. In a real production script, I would put in a lot more error checking between commands and also create filters for the Active Directory query because OUs can contain computers and other types of objects such as users, groups, and contacts.

If you want to see how this script runs on your own system, open your text editor and type it in (or use the file for this listing on the book's Web site). You have to change the LDAP path to an existing OU within your Active Directory, then save it as complist.psl. Now run this script and watch the magic happen.

Tip: You'll see that some lines end with a backtick (`) character. This means that the next line is just a continuation of the current line and not a separate command. This is useful if you have very long commands that you want to break up into multiple lines rather than have them keep going on and on to the right.

Warning: Don't confuse the backtick (`) with the single quote ('). The backtick character is typically found to the left of the number 1 key on U.S. keyboard (usually above the tab key).

This is an excerpt from:

Windows PowerShell 2 is the scripting language that enables automation within the Windows operating system. Packed with powerful new features, this latest version is complex, and Windows PowerShell 2 For Dummies is the perfect guide to help system administrators get up to speed. Written by a Microsoft MVP with direct access to the program managers and developers, this book covers every new feature of Windows PowerShell 2 in a friendly, easy-to-follow format.

Windows PowerShell 2 is the updated scripting language that enables system administrators to automate Windows operating systems
System administrators with limited scripting experience will find this book helps them learn the fundamentals of Windows PowerShell 2 quickly and easily
Translates the jargon and complex syntax of Windows PowerShell 2
Covers script debugging improvements, the ability to invoke commands remotely, and the new user interface
Uses real-world applications to clarify the theory, fundamentals, and techniques of the scripting language

Windows PowerShell 2 For Dummies makes this tool easily accessible to administrators of every experience level.

More Windows Administration Information:
• How to Erase a Hard Disk Drive Permanently
• How to Disable Windows Firewall in Windows 7
• SMART Disk Drives Warn You Before They Fail
• Script to Print a Directory File List
• Windows PC Performance Troubleshooting and Optimisation
• PC Technician Certifications and Professional Organizations
• Put HyperTerminal on Windows 7
• How to Change Process Priorities in Windows Task Manager
• Configure Windows 10 to Search Windows Only
• How to Audit Security Permissions and Access Rights in Active Directory

RSS Feed RSS Feed


Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2018 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268