header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left

[BANNER]

[BANNER]

This area of the Web site is freely editable by all registered users. When editing, expand the "Directions" item for instructions on creating and linking to new pages. Please help keep this area of the community neat and clean by adding appropriate edits and so forth.

This area of the Web site is freely editable by all registered users. When editing, expand the "Directions" item for instructions on creating and linking to new pages. Please help keep this area of the community neat and clean by adding appropriate edits and so forth.

EmitObjects


Whenever possible, functions (especially) and scripts (to a lesser degree) should emit custom objects, not just text. This ensures that the output of these constructs can be piped to other cmdlets, like Where-Object, Sort-Object, and so forth, further extending PowerShell's capabilities.

To create a custom object:

$obj = New-Object PSObject

To add properties to the object:

$obj | Add-Member NoteProperty "MyPropertyName" "MyValue"

And repeat as needed to add additional properties. Then output the object to the pipeline:

Write $obj

These output objects can then be sorted, grouped, filtered, and so forth, making your code behave more like a "real" PowerShell cmdlet.

Contributed by Don Jones




 |  View Topic History  |
right
footer   footer
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
footer   footer