Formatting AD Objects

Welcome Forums General PowerShell Q&A Formatting AD Objects

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

10 months ago.

  • Author
  • #99292

    Points: 4
    Rank: Member

    I am finally getting around to creating formatting (ps1xml) for the output of my functions. I have one function that returns objects of type Microsoft.ActiveDirectory.Management.ADGroup. I would like to have the default output for this function to still be an ADGroup object (so I don't want to change the TypeName). But I want to format the output for this function differently than the default (format-table instead of format-list).

    I know that formatting in the script with a format-table makes the output not be an ADGroup any more (and is bad practice anyway). I could run the function and pipe it into format-table to get what I want, but would like to have a different default output format so I don't have to remember to do that each time.


  • #99445

    Points: 101
    Helping Hand
    Rank: Participant

    Take a look at the results from Iron script prequel 2 – great way to look at formatting your code just the way you want.

  • #99450

    Points: 1
    Rank: Member

    Hey Darwin,
    It sounds like you have a slight miss-understanding of the output. Powershell will, by default, change between using Format-Table or Format-List for its output based on the number of properties passed for the object being displayed.
    4 or less properties and it will default to Format-Table. 5 or more properties and it will default to Format-List (Ref:

    So there are a few options available to you.
    1) You can use Select-Object and select 4 or less properties you actually want output and it will default to Format-Table
    2) You can Pipe the output to the formatter you wish to use each time so it is formatted as you desire. IE. | Format-Table
    3) You can change the default behavior and write your own output handling in the Out-Default cmdlet. (Ref:

  • #99538

    Points: 4
    Rank: Member

    Aha! Select-Object does not change the object type, so it remains an ADGroup object type. I didn't realize that. This is exactly what I needed. Thanks.

The topic ‘Formatting AD Objects’ is closed to new replies.

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