Showing selected properties in a new object?

If you have a look at cmdlets like New-ADUser and such they have a hole lot of properties but only display three or four on the default output.

If I were to create a custom object how can i choose certain properties to show in the default output of the custom cmdlet i am creating?

First, your custom object must have a unique name.

$object.psobject.typenames.insert(‘My.Unique.Name’)

From there, you either:

Create and load a custom view, like a table or a list, that shows what you want.

Or:

Create and load a type extension that defines a DefaultDisplayPropertySet. Only those properties will display by default.

These are usually easiest to do if the code that creates your custom object is in a module. You can use the module’s manifest to also load the custom view and/or custom type extension as part of the module, so that it all happens transparently.

“PowerShell In Depth” covers all of this. You can also review the help for Update-FormatData and Update-TypeData, although they do not completely document the XML syntax. In the $pshome folder you will find the .ps1xml file (type extensions) and .format.ps1xml files (format views) that PowerShell ships with. I’ve used those as examples in the past.