Starting with this bit of code from this answer:
stringList.ForEach(item => listBox1.Items.Add(item));
I've put my own variables into the line like so:
$listAgencies = $Window.FindName('listAgencies')
$arr_listAgencies = ($hash_AgencyOffices['ADMIN1','ADMIN2'].Keys | ForEach-Object ToString)
$arr_listAgencies.ForEach(item => $listAgencies.Items.Add(item))
I have confirmed that $arr_listAgencies is a list of the values I need in the ListBox $listAgencies, but I'm guessing I am entirely missing the importance of item in that last line: (item => $listAgencies.Items.Add(item)).
When I run this PS kindly informs me that there is a missing ')' in method call and there is an unexpected token 'item' in expression or statement.
Is item supposed to be $._, the pipeline variable? I thought that might have been it and tried it, but the error was essentially the same.
What am I missing?