PSCustomObject View

Welcome Forums General PowerShell Q&A PSCustomObject View

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

 
Participant
4 years, 3 months ago.

  • Author
    Posts
  • #18030

    Participant
    Points: 0
    Rank: Member

    Hi everyone,

    This is my first post, but I'm really hoping you can help me out, this is driving me nuts.....

    When you create a cmdlet or function that outputs a System.Management.Automation.PSCustomObject type, how do you show a custom view in the console? If i create an object with 30 properties and I only want to show 4 in the console table view, how can i keep all the object properties in tact to pass to the pipeline, but view only the 4 columns until I pipe it to select or format etc....

    I know you can format custom types in the format.ps1xml file but wouldn't that change the format for every PSCustomObject type that was created?

    I'm missing something obvious probably 🙂

    Cheers
    Toby

  • #18031

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    You have to give it a custom type name.

    $obj.psobject.typenames.insert(0,"my.type.name")

    All covered in my Toolmaking book 🙂

  • #18032

    Participant
    Points: 0
    Rank: Member

    Cheers Don,

    That is way simpler than Visual Studio and dll's – thanks so much!!!

    Trying to get time to read all your stuff – my girlfriend isn't that impressed that I've printed off the dsc book and brought it home 🙂

    Cheers
    Toby

The topic ‘PSCustomObject View’ is closed to new replies.