array not filling

Welcome Forums General PowerShell Q&A array not filling

Viewing 1 reply thread
  • Author
    Posts
    • #164151
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      Good day,
      I am working on an export. And probably I make a very simple mistake, but I am unable to discover what I’m doing wrong.
      Its a big script but I will only copy the relevant portion of it
      $verzameling = @()

      here is looping code with all kind of stuff and in this stuff is
      1. if ($flag -eq “1”){
      2. ($feedback.servers.($id)).servers[$i].hostname
      3. $verzameling += ($feedback.servers.($id)).servers[$i].hostname
      4. Write-host “$(($feedback.servers.($id)).servers[$i].hostname) ***************************” -ForegroundColor Green
      5. }

      I numbered the lines (of course only here)
      Line 2 I added to test if the variable is filling the right way and the right value is shown when run. So I know the array does not stay empty because the input is not empty.
      Line 4 is for feedback for the person who runs the script and this line is working aswel.
      Line 3 is the line where I want to add every server that has flag -eq 1 according to line 1 to be added to the array $verzameling

      The weird thing is when I manually type line 3 and $i = 0 the line is added. But when running the script the array stays empty.

      Thank you for taking the time to read my message 🙂

       

    • #164193
      js
      Participant
      Topics: 30
      Replies: 828
      Points: 2,554
      Helping Hand
      Rank: Community Hero

      Wow, how did you make this?

      ($feedback.servers.($id)).servers[$i].hostname
      
      • #164199
        Participant
        Topics: 1
        Replies: 1
        Points: 14
        Rank: Member

        Its input I get from a program through api 🙂

Viewing 1 reply thread
  • The topic ‘array not filling’ is closed to new replies.