Hi all,
Let me specify what I’m struggling with here:
I have a dynamic array where I don’t know what entries or values will be added in forehand. The array then has to be converted to Json
Here is my problem:
When two values share the same entry name, how do you append to that entry?
My code:
$Body = New-Object System.Collections.ArrayList
If ($PSBoundParameter.ContainsKey('NTPEnabled')) {
[void]$Body.Add(
@{
NTP = @{
ProtocolEnabled = $NTPEnabled
}
}
)
}
If ($PSBoundParameter.ContainsKey('NTPServers')) {
[void]$Body.Add(
@{
NTP = @{
NTPServers = @(
$NTPServers | ForEach-Object {
$_
}
)
}
}
)
}
If both is used, PowerShell outputs the following:
Name Value —- —– NTP NTPServers=x.x.x.x,y.y.y.y NTP ProtocolEnabled=true
The values both share the same entry, but they are indivual entries inside NTP.
I read somewhere about nested arrays, but im not sure.
Any help is appreciated.
Thanks in advance!