Showing selected properties in a new object?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 10 months, 3 weeks ago.

  • Author
  • #32669
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan

    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?

  • #32670
    Profile photo of Don Jones
    Don Jones

    First, your custom object must have a unique name.


    From there, you either:

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


    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.

You must be logged in to reply to this topic.