Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

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:
• Video Tutorial 3 - The Windows 7 Backup and Restore Utility
• Put HyperTerminal on Windows 7
• For Quick Information About System - DOS Systeminfo Command
• Create a Shortcut to Windows 10 Services Management Console
• Script to Print a Directory File List
• How to Setup a VPN Between Two Computers
• Security Risks and Ways to Decrease Vulnerabilities in a 802.11b Wireless Environment
• What is Hyper-V in Windows Server 2019?
• Set the User's Profile Information
• Tweaks to Speed Up Internet Streaming Video

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-2022 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268