PowerShell shortest syntax to create a new PSObject using Property?

Question:

I use the following very often:

I would like to make this as short as possible, perhaps even 1 character?
What’s the shortest way to create a new psobject using the properties above?

My desire is that I could do it with a syntax similar to this:

Note that I replaced the @ with a new ‘special’ symbol.

Note, if this is considered off-topic, I will move it.

Answer:

PowerShell 3 and later support this syntax:

One of the added benefits is that the properties are ordered, unlike a standard call to New-Object.

You add overhead, but presumably you could create your own type accelerator that does something similar to pscustomobject, and use a shorter name : ) Not sure what goes on under the hood of pscustomobject though.

Source:

PowerShell shortest syntax to create a new PSObject using Property? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply