Solved

In Powershell, need to find way to grab all computer names from a given AD OU

Posted on 2008-06-18
3
834 Views
Last Modified: 2010-04-21
I'm trying to do this efficiently, as I've already accomplished this in a not-so-elegant way.
Using the command "Get-QADComputer" from Quest AD Snapin and specifying the scope then doing a pipe and "select-object -property name", I end up with a nice little array full of computer names and related properties from AD.  When I attempt to use the name as a Get-WMIObject -computer <computer name>, it's not working so well.

It comes out like @{Name=<computername>} and I have to do an old-fashioned text parse to get it to work.  I don't think this is necessary in Powershell.  In VBScript it would be though.

Currently, I've tried various ways to do this.  I have a subroutine set up for a command like
getdrive $computer, but that's after I've parsed the names from their old form of @{Name=}.  I'm trying to find a one liner:

Get-QADComputer -scope <domain> | ?{getdrive $_}

My Function for the GetDrive is something along the lines of

Function Getdrive{
$ColDisks = Get-WMIObject W32Logicaldisk -computername $args
<more code>
}

So, I can't do a one liner for the Get-WMIObject because I have quite a bit of code needing to processed in my function... or can I?

Any help?
0
Comment
Question by:Dale Harris
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
BSonPosh earned 500 total points
ID: 21814829
Get-WMIObject takes an Array of Strings for ComputerName so you could just do this

$servers = Get-QADComputer | select dnsName
Get-WMIObject Win32_Logicaldisk -computername $servers

or

Get-QADComputer | ?{getdrive $_.dnsHostName}

Note: Your using where-object which expects getdrive to return $true or $false.
0
 
LVL 16

Author Comment

by:Dale Harris
ID: 21820094
BSonPosh,

Again, you came through with the answer.  I ended up using the second choice.  And I had to tweak my script and ended up using "$_.name" as a variable to show which computer had the hard drive space association.  But that was in my function only, and outside the function, $_.dnsHostname worked very well.  

Your valuable experience and dedication to helping others reflects great credit upon yourself, your company and Experts Exchange.

-Dale Harris
0
 
LVL 16

Author Closing Comment

by:Dale Harris
ID: 31468454
Your valuable experience and dedication to helping others reflects great credit upon yourself, your company and Experts Exchange.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question