I'm trying to add an array of hashtables to an existing array of hastables in Powershell, adding a single item works fine but I can't seem to find out how to add multiple hashtables to an existing array.
For example I have the below;
$ToAdd = @()
$ToAdd += (@{
id = "1234";
type = "Scope";
})
I then want to be able to add the $ToAdd array of hashtables to the object below ($helloBody.helloAccess.AccessRequired)
$HelloBody = [ordered] @{
"helloAccess" = @(
@{
hello = "hello"
accessRequired = @(
@{
id = "random guid"
type = "item 123"
}
)
}
)
}
How is it possible to add an array of hashtables into another array?
When I try $helloBody.helloAccess.AccessRequired += $ToAdd, I get the following error:
A hash table can only be added to another hash table.