Creating Custom Objects

by Nov 4, 2009

PowerShell v.2 has a new trick for creating your very own objects that you can then pass to other cmdlets. It is a two-step process. First, create a hash table and add all the information you want in your object:

$hash = @{}
$hash.name = "Tobias"
$hash.Age = 85
$hash.hasDog = $true

Next, use this line to convert the hash table into an object:

$object = new-object PSObject -property $hash
$object

Twitter This Tip! ReTweet this Tip!