Structs or Objects in Powershell 2

Question!

Does the latest version of Powershell have the ability to do something like JavaScript's:

var point = new Object();
point.x = 12;
point.y = 50;

If not, what is the equivalent or workaround?

UPDATE
Read all comments

By : BuddyJoe


Answers

For simple ways, first, is a hashtable (available in V1)

$obj = @{}
$obj.x = 1
$obj.y = 2

Second, is a PSObject (easier in V2)

$obj = new-object psobject -property @{x = 1; y =2}

It gives you roughly the same object, but psobjects are nicer if you want to sort/group/format/export them

By : mrwaim


$point = "" | Select @{Name='x'; Expression={12}} ,@{Name='y'; Expression={15}}

or more intuitively

$point = "" | Select x,y
$point.x=12; $point.y=15


Sorry, even though the selected answer is good, I couldn't resist the hacky one line answer:

New-Object PsObject | Select-Object x,y | %{$_.x = 12; $_.y = 50; $foo = $_; }
By : EBGreen


This video can help you solving your question :)
By: admin