?
Solved

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

Posted on 2008-06-18
3
Medium Priority
?
842 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 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