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

x
?
Solved

Adding items to ArrayList prints ArrayList index to the screen

Posted on 2011-04-22
3
Medium Priority
?
763 Views
Last Modified: 2012-05-11
When I add items to ArrayList, Powershell also outputs the ArrayList index to the screen. How do i prevent that from happening?

Here is my code:
 
$alComputers=new-object Collections.ArrayList
foreach ($child in $ou.psbase.Children) { 
    	if ($child.ObjectCategory -like '*computer*') { 
		$alComputers.Add($child)
	} 
}

Open in new window

0
Comment
Question by:YZlat
  • 2
3 Comments
 
LVL 13

Assisted Solution

by:soostibi
soostibi earned 2000 total points
ID: 35447501
For example this way:
$alComputers=new-object Collections.ArrayList  
foreach ($child in $ou.psbase.Children) {   
        if ($child.ObjectCategory -like '*computer*') {   
                $alComputers.Add($child) > $null
        }   
}

Open in new window

0
 
LVL 13

Accepted Solution

by:
soostibi earned 2000 total points
ID: 35447506
Other alternatives:

$alComputers.Add($child) | Out-Null

[void] $alComputers.Add($child)
0
 
LVL 35

Author Comment

by:YZlat
ID: 35447552
Thanks a bunch!
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
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 anti-spam), the admin…
Loops Section Overview

873 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