Dynamically create objects

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?

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.