Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I summarize an object the same way Format-List does?
    primarykey
    data
    text
    <p>For example, looking at a processes threads shows something like this:</p> <pre><code>PS C:\&gt; (Get-Process)[0] | Format-List -Property Threads Threads : {1548, 1600, 15940, 13996} </code></pre> <p>But if you actually grab that property directly, it looks like this:</p> <pre><code>PS C:\&gt; (Get-Process)[0].Threads BasePriority : 8 CurrentPriority : 9 Id : 1548 IdealProcessor : PriorityBoostEnabled : PriorityLevel : PrivilegedProcessorTime : StartAddress : 8790537024736 StartTime : ThreadState : Wait TotalProcessorTime : UserProcessorTime : WaitReason : UserRequest ProcessorAffinity : Site : Container : BasePriority : 8 ... etc </code></pre> <p>Format list obviously has a method to summarize objects intelligently. It took a list of objects, pulled out a representative property from each one, and displayed it as a short array. I cannot find a method or cmdlet that allows me to summarize an collection of objects in the same manner.</p> <p>I want to be able to pass an arbitrary collection of objects to a method and have it summarize. This is used when listing email addresses in Exchange objects, listing groups in AD objects, and many other places... I doubt these are all special cases.</p> <hr> <p>To expand (after learning more from @JoelSmith's comments):</p> <p>.NET Objects have <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/gg580992(v=vs.85).aspx" rel="nofollow noreferrer">formatting definitions</a> that are used by Powershell when <a href="https://superuser.com/questions/469980/how-does-formatting-works-with-a-powershell-function-that-returns-a-set-of-eleme">formatting output</a>. Additional details are available using <code>help about_Format.ps1xml</code><a href="http://technet.microsoft.com/en-us/library/hh847831.aspx" rel="nofollow noreferrer">[1]</a>. These definitions are generic and can be accessed by any command, but by default there are no functions in Powershell to directly retrieve the output of an object property directly as it would be displayed in Format-List.</p> <p>One hackish workaround is to split and strip the output like so:</p> <pre><code>(Get-Mailbox user | Format-List -Property Languages | Out-String).Split(':')[1].Trim() # =&gt; {en-US,fr-CA} </code></pre> <p>However this method is extremely fragile, and will fail when the output spans multiple lines or contains a colon in the output:</p> <pre><code>(Get-Mailbox user | Format-List -Property EmailAddresses | Out-String).Split(':')[1].Trim() # =&gt; {smtp </code></pre> <p>What is needed is a method that reads the formatting definition defined for the object and retrieves it directly, then use it to output the desired string. I have failed to find any example online.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload