[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Retrieve a list of computers grom a particular OU

Posted on 2011-04-21
10
Medium Priority
?
419 Views
Last Modified: 2012-05-11
Can someone help me with a script that would return a list of computer objects from a particular AD group.

Here is what I got so far:

 
$ou = [ADSI]"LDAP://OU=MyGroup,OU=Section1,DC=domainname,DC=com"
foreach ($child in $ou.psbase.Children) { 
    	if ($child.ObjectCategory -like '*computer*') { 
		Write-Host $child.Name 
	} 
}

Open in new window

0
Comment
Question by:YZlat
  • 5
  • 4
10 Comments
 
LVL 1

Expert Comment

by:BlackSnowman
ID: 35443718
LDAP://OU=YOUROU,DC=DOMAIN,DC=LOCALldap://OU=YOUROU,DC=DOMAIN,DC=LOCAL">LDAP://OU=YOUROU,DC=DOMAIN,DC=LOCAL</A< A>>
foreach ($child in $ou.psbase.Children )
{
  if ($child.ObjectCategory -like '*computer*')
{
Write-Host $child.Name
}
}
0
 
LVL 35

Author Comment

by:YZlat
ID: 35443843
BlackSnowman, that's exactly what I have.

Except, where do you assign a value to variable $ou?
0
 
LVL 12

Accepted Solution

by:
rlandquist earned 2000 total points
ID: 35444180
Your syntax is fine.  What error are you getting?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:rlandquist
ID: 35444560
Try this version:
$ADsPath = [ADSI]"LDAP://OU=Ellsworth,DC=Ellsworth,DC=com"
$Search = New-Object DirectoryServices.DirectorySearcher($ADsPath)
$Search.filter = "(objectClass=computer)"
$Search.PageSize = 1000
$Search.SearchScope = "subtree" 
$results = $Search.Findall()

foreach ($result in $results)
{
    $Computer = $result.GetDirectoryEntry()
   $Computer.Name
}

Open in new window

0
 
LVL 35

Author Comment

by:YZlat
ID: 35447013
no error, it just does not do anything, no output to the screen
0
 
LVL 12

Expert Comment

by:rlandquist
ID: 35447076
Did you change the 1st line to point to your OU and domain?
Where in AD are the computers you are trying to list?
0
 
LVL 12

Expert Comment

by:rlandquist
ID: 35447080
Was your comment to my question about the error, or my new script?
0
 
LVL 35

Author Comment

by:YZlat
ID: 35447095
rlandquist, my code worked, turns out I was not running it the correct way.

Could you tell me how to put all the returned data into an array instead of printing it to the screen?
0
 
LVL 12

Expert Comment

by:rlandquist
ID: 35447214
Please show the code you are using now.
0
 
LVL 35

Author Comment

by:YZlat
ID: 35447361
Nevermind, I figured it out. I have another question but since it is a different question, I am gonna open a new request. Could you help me there?

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_26971979.html
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

834 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