List View (GroupBy)
This example shows how to implement a list view that separates the rows of the list into groups. This list view displays the properties of the System.ServiceProcess::ServiceController objects returned by the Get-Service cmdlet. For more information about the components of a list view, see Creating a List View.
To load this formatting file
Copy the XML from the Example section of this topic into a text file.
Save the text file. Be sure to add the format.ps1xml extension to the file to identify it as a formatting file.
Open Windows PowerShell, and run the following command to load the formatting file into the current session: Update-formatdata –prependpath PathToFormattingFile.
Warning This formatting file defines the display of an object that is already defined by a Windows PowerShell formatting file. You must use the prependPath parameter when you run the cmdlet, and you cannot load this formatting file as a module.
Demonstrates
This formatting file demonstrates the following XML elements:
The Name element for the view.
The ViewSelectedBy element that defines what objects are displayed by the view.
The GroupBy element that defines how a new group of objects is displayed.
The ListControl element that defines what property is displayed by the view.
The ListItem element that defines what is displayed in a row of the list view.
The PropertyName element that defines which property is displayed.
Example
The following XML defines a list view that starts a new group whenever the value of the ServiceController::Status property changes. When each group is started, a custom label is displayed that includes the new value of the property.
<Configuration>
<ViewDefinitions>
<View>
<Name>System.ServiceProcess.ServiceController</Name>
<ViewSelectedBy>
<TypeName>System.ServiceProcess.ServiceController</TypeName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>Status</PropertyName>
<Label>New Service Status</Label>
</GroupBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>DisplayName</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ServiceType</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
The following example shows how Windows PowerShell displays the System.ServiceProcess::ServiceController objects after this format file is loaded. The blank lines added before and after the group label are automatically added by Windows PowerShell.