Dynamically create objects

Welcome Forums General PowerShell Q&A Dynamically create objects

Viewing 1 reply thread
  • Author
    Posts
    • #199337
      Participant
      Topics: 7
      Replies: 10
      Points: 113
      Rank: Participant

      Hello,

      I want to create chart with ping result from few servers (they addresses are readed from file). It require to create new series for each server using command:

      $series1 = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series //for fist server,
      $series2 = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series //for second server
      etc.

      Now I wanted to redesign script that it will count number of servers from file, and based on that number, created the right number of $series.
      For example “something” like in the code below:

      $i=1
      foreach ($server in $servers.PSObject.Properties.Name -notmatch "timestamp"){
      New-Variable "Series$i" 
      "Series$i" = New-Object -TypeName 
      System.Windows.Forms.DataVisualization.Charting.Series
      $i ++
      }

      But this is not working… How can I resolve this problem?

      • This topic was modified 2 months, 1 week ago by kolaborek08.
      • This topic was modified 2 months, 1 week ago by kolaborek08.
    • #199370
      Participant
      Topics: 12
      Replies: 1489
      Points: 1,987
      Helping Hand
      Rank: Community Hero

      Take a look at this thread:

      https://social.technet.microsoft.com/Forums/en-US/bc6af53d-b392-49f3-80d0-0b36157c87be/charting-with-powershell?forum=winserverpowershell

      Also note that there are other options rather than this charting also referenced in the above thread.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.