Adding items to ArrayList prints ArrayList index to the screen

Posted on 2011-04-22
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*') { 

Open in new window

Question by:YZlat
    LVL 13

    Assisted Solution

    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

    LVL 13

    Accepted Solution

    Other alternatives:

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

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

    Author Comment

    Thanks a bunch!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A post on a forum I visit frequently mobilized me to create a script to remove a password (the one required to open a file) from any number of Word files. Because nobody would want to open a 100 files and manually save them... Of course, you have t…
    The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now