You can do both. To add a value to a hash table then just use the dictionary syntax.
$output = @{ "Hostname" = "host`"; "RDP_Pass" = $true }
$output["NewProperty"] = 10
This would add a value to the current object which is a hash table. If you need to store per-server info then do this. Personally I find it better to go ahead and add all the properties up front defaulted to some value and then set them later if needed rather than dynamically adding them in as you go.
For adding to an array then a PS array can be added to.
$items = @()
$items += 10
But if you try to call Add
you'll get an error because Add
isn't a valid call. PS array is an actual array so when you use += it creates a new array, copies the original values over, adds the new value and returned the updated array. If you're going to be doing this a lot then it is inefficient. At that point the better approach is to switch to a List which handles the details.
$list = New-Object Collections.ArrayList
$list += 10
$list.Add(20)
ArrayList
is equivalent to the PS array and you can store anything in it. If you want to only store a specific type then prefer the generic version instead.
[System.Collections.Generic.List[int]] $integersOnly = @()
$integersOnly += 10
$integersOnly.Add(20)
$integersOnly.Add("Hello") # Error