Solved

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

Posted on 2008-06-18
3
832 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
Comment Utility
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
Comment Utility
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
Comment Utility
Your valuable experience and dedication to helping others reflects great credit upon yourself, your company and Experts Exchange.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now