Powershell’s adding Integers when populating arrayList

Question:

I have a function in Powershell which populates a list with dictionaries.

Instead of receiving an ArrayList which returns only Hashtables it returns a list which has Int32 and Hashtable, where there is an Int32 in it for each hashtable element:

I’m not really sure why I have those integers in my ArrayList.

Answer:

The problem here is that ArrayList.Add() returns the index at which the new item was added. When you return $control_list, the integers representing the index locations have already been written to the pipeline

Prefix the method call with [void] to remove the output from Add():


Or pipe to Out-Null:

Source:

Powershell’s adding Integers when populating arrayList by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply