How to display all items in a member from Powershell without “…”

前端 未结 2 395
灰色年华
灰色年华 2021-01-25 15:01

Run the following command:

Get-ADUser  -properties MemberOf | select MemberOf | Format-List *

results in something like

2条回答
  •  借酒劲吻你
    2021-01-25 15:41

    Use Select-Object's -ExpandProperty switch:

    Get-ADUser  -Properties MemberOf | select -ExpandProperty MemberOf
    

    When you use Select-Object to filter for certain properties, it returns a PSCustomObject containing the specified properties of the object selected (or an array of PSCustomObjects, if multiple objects are selected). With -ExpandProperty, which may be used with only a single property, for each object selected it returns the object contained in the specified property.

    So, with | select MemberOf, what's being returned is a PSCustomObject whose sole property is the MemberOf property of the ADUser object returned by Get-ADUser, displayed in list format (in the same style as it would display the results if you were listing multiple properties of the object).

    With | select -ExpandProperty MemberOf, what's being returned is the ADPropertyCollection object which is contained in the MemberOf property (a collection of strings representing the DNs of the members), and that's the object that's displayed in list format.

    BTW, I removed the | Format-List * because it's superfluous in this case.

提交回复
热议问题