0

I'm adding items to an array called $MissingIps using the following command

$MissingIps = @("")
[System.Collections.ArrayList]$ExistingIps = $MissingIps
if ($lbips -notcontains $awsip){
    $MissingIps.Add("$awsip")
}

On execution, PowerShell automatically echos the index position, and I'm struggling to hide that.

Any ideas?

2 Answers 2

2

As an alternative to the suggested methods of suppressing the unwanted output: don't use an ArrayList collection in the first place. It's the Add() method of that class that generates the output. If you use a regular array you can append without output being generated:

$MissingIps = @()
if ($lbips -notcontains $awsip){
    $MissingIps += $awsip
}
Sign up to request clarification or add additional context in comments.

Comments

1

This will do the work:

$MissingIps = @("")
    [System.Collections.ArrayList]$ExistingIps = $MissingIps
    if ($lbips -notcontains $awsip){
        $MissingIps.Add("$awsip") | out-null
    }

3 Comments

other possibilities are [void]$MissingIps.Add("$awsip") and (but uglier) $null = $MissingIps.Add("$awsip")
@MickyBalladelli: yup. or we can redirect that to $MissingIps.Add("$awsip") >> $null
@RanadipDutta Thanks. Your original solution did the trick :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.