18 March 2014

Custom object - the easy way

the hard way:

$customObject = New-Object PSObject
$customObject | Add-Member NoteProperty Name "Marius"
$customObject | Add-Member NoteProperty Age "33"
$customObject | Add-Member NoteProperty Country "Romania"



the easy way:

$customObject = " " | Select-Object Name, Age, Country
$customObject.Name = "Marius"
$customObject.Age = "33"
$customObject.Country = "Romania"

1 comment:

  1. The super easy way ;)

    [PSCustomObject]@{Name = "Marius";Age = 33;Country = "Romania"}

    ReplyDelete