Creating Object Arrays on the Fly

by Mar 14, 2017

Here is a quick code sample that generates an array of objects using the built-in CSV parser:

$csv = @'  
PC,Date
PC82012,2017-02-28
PC82038,2017-02-28
PC83073,2017-02-28
PC84004,2017-02-28
PC84009,2017-02-28
PC84015,2017-02-28
PC90435,2017-02-28
'@

$data = $csv | ConvertFrom-Csv 

$data
$data | Out-GridView

This can be useful if a script requires a constant (static) list of servers, connection data, or other pieces of information.

Twitter This Tip! ReTweet this Tip!