Showing selected properties in a new object?

Welcome Forums General PowerShell Q&A Showing selected properties in a new object?

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 5 months ago.

  • Author
  • #32669

    Topics: 58
    Replies: 89
    Points: 3
    Rank: Member

    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Showing selected properties in a new object?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort