Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
843 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

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
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, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

604 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