[Array] How to append to an entry name?

Welcome Forums General PowerShell Q&A [Array] How to append to an entry name?

Viewing 1 reply thread
  • Author
    Posts
    • #197357
      Participant
      Topics: 2
      Replies: 0
      Points: 23
      Rank: Member

      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:

      If both is used, PowerShell outputs the following:

      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!

      • This topic was modified 8 months, 1 week ago by kvprasoon. Reason: code formatting
    • #197369
      Participant
      Topics: 15
      Replies: 1761
      Points: 3,167
      Helping Hand
      Rank: Community Hero

      Please read the pinned posting at the top of the forum and highlight your code and output with the PRE. Assuming you are putting this together for a JSON body, {} are hashtable and [] are arrays, so the code should look soemthing like this:

      Output:

      In the function for something like ProtocolEnabled, I would set a default value and remove the PSBoundParameters IF to always create a NTP part of the body, otherwise you will need to wrap the $ntp.Add with an IF statement to see if there were any passed values for Protocol or NTPServers.

      • This reply was modified 8 months, 2 weeks ago by Rob Simmers.
Viewing 1 reply thread
  • The topic ‘[Array] How to append to an entry name?’ is closed to new replies.