Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell: Reusable Custom Object?

$
0
0
$out = @()

$base = New-Object PSObject -Properties @{
   'Name' = ''
   'Version' = ''
   'Foo' = ''
}

$one = $base
$one.Name = "test"
$one.Version = "1"
$one.Foo = "bar"
$out += $one

$two = $base
$two.Name = "test 2"
$two.Version = "2"
$two.Foo = "bar2"
$out += $two

The above does not work as written. $out ends up being only 2 objects that have the same values. But I'm just wondering if there is a simple/elegant way to "stage" an object and then reuse it multiple times in this fashion?

Thanks!

Edit: It's almost like a need a "new" constructor.

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>