Idera nSoftware Compellent

Creating Custom Objects

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!


Posted Nov 04 2009, 08:00 AM by ps1

Comments

uberVU - social comments wrote Social comments and analytics for this post
on 11-04-2009 4:06 PM

This post was mentioned on Twitter by PowerTip: Creating Custom Objects in #PowerShell http://bit.ly/VaWrR

Twitter Trackbacks for Creating Custom Objects - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for Creating Custom Objects - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 11-04-2009 4:10 PM

Pingback from  Twitter Trackbacks for                 Creating Custom Objects - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Copyright 2010 PowerShell.com. All rights reserved.