I have been working on a script that has an interactive cli menu to select from. I've got everything working and the script itself works but for some reason the selection menu (formatted as an ArrayList object) won't display during run when called, rather it displays at the end of script. What am I missing?
[System.Collections.ArrayList] $menuarray = @() # init blank array
$somelist1 = Get-SomeDataHere | ConvertFrom-Json
$init = 0
while ($init -ne $somelist1.items.Count)
{
$menuarray.add([PSCustomObject]@{Number = $init;somenamedthing = $somelist1.items.metadata.name[$init];someaddress = $somelist1.items.status.someaddress[$init]}) > $null
$init = $init+1
}
write-host "Printing Array"
$menuarray
$menuselection = -1
While($menuselection -notin 0..$somelist1.items.count) # simple while loop to require the user to enter a selection from the list.
{
write-host "Specify number of items you would like to interact with:"
$menuselection = Read-host
}
write-host "You picked $menuselection with associated address of:" $somelist1.items.status.someaddress[$menuselection]
I've tried running the script section outside (directly in powershell so I can see what is happening), tried calling the $menuarray in different areas, with echo, without echo, etc.