Create PowerShell Object


Hereunder a little reminder about how to create object in all version of PowerShell :

PowerShell 1

#PowerShell v1
$Computer = "" | select Name, State, OS
$Computer.Name = "Localhost"
$Computer.State = "Unknown"
$Computer.OS = "Unknown"


PowerShell 2

#PowerShell v2
$Computer = New-Object -TypeName PSObject -Property @{Name = "Localhost"; State = "Unknown"; OS = "Unknown"}


PowerShell 3

#PowerShell v3
[PsCustomObject]@{Name = "Localhost"; State = "Unknown"; OS = "Unknown"}


If you look at performances :


Please upgrade to the latest PowerShell version you can if you want to have maximum performances.

0 thoughts on “Create PowerShell Object

  1. Pingback: Add custom type to a PowerShell Custom Object - It For DummiesIt For Dummies

  2. Pingback: Add custom method to custom object - It For DummiesIt For Dummies

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.