Solved

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

Posted on 2008-06-18
3
838 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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