List View (Labels)

This example shows how to implement a list view that displays a custom label for each row of the list. This list view displays the properties of the System.ServiceProcess.ServiceController object that is 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

  1. Copy the XML from the Example section of this topic into a text file.

  2. Save the text file. Be sure to add the format.ps1xml extension to the file to identify it as a formatting file.

  3. Open Windows PowerShell, and run the following command to load the formatting file into the current session: Update-formatdata –prependpath PathToFormattingFile.

    Warning Caution:
    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 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 Label 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 displays a custom label in each row. In this case, the label includes the property name with each letter capitalized and the word “property”. In each row, the name of the property is displayed followed by the value of the property.

<Configuration>  
  <ViewDefinitions>
    <View>
  <Name>System.ServiceProcess.ServiceController</Name>
  <ViewSelectedBy>
    <TypeName>System.ServiceProcess.ServiceController</TypeName>
  </ViewSelectedBy>
  <ListControl>
    <ListEntries>
      <ListEntry>
        <ListItems>
          <ListItem>
            <Label>NAME property</Label>
            <PropertyName>Name</PropertyName>
          </ListItem>
          <ListItem>
            <Label>DISPLAYNAME property</Label>
            <PropertyName>DisplayName</PropertyName>
          </ListItem>
          <ListItem>
            <Label>STATUS property</Label>
            <PropertyName>Status</PropertyName>
          </ListItem>
          <ListItem>
            <Label>SERVICETYPE property</Label>
            <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.

PS> get-service f*
NAME property        : Fax
DISPLAYNAME property : Fax
STATUS property      : Stopped
SERVICETYPE property : Win32OwnProcess

NAME property        : FCSAM
DISPLAYNAME property : Microsoft Antimalware Service
STATUS property      : Running
SERVICETYPE property : Win32OwnProcess

NAME property        : fdPHost
DISPLAYNAME property : Function Discovery Provider Host
STATUS property      : Stopped
SERVICETYPE property : Win32ShareProcess

NAME property        : FDResPub
DISPLAYNAME property : Function Discovery Resource Publication
STATUS property      : Running
SERVICETYPE property : Win32ShareProcess

NAME property        : FontCache
DISPLAYNAME property : Windows Font Cache Service
STATUS property      : Running
SERVICETYPE property : Win32ShareProcess

NAME property        : FontCache3.0.0.0
DISPLAYNAME property : Windows Presentation Foundation Font Cache 3.0.0.0
STATUS property      : Stopped
SERVICETYPE property : Win32OwnProcess

NAME property        : FSysAgent
DISPLAYNAME property : Microsoft Forefront System Agent
STATUS property      : Running
SERVICETYPE property : Win32OwnProcess

NAME property        : FwcAgent
DISPLAYNAME property : Firewall Client Agent
STATUS property      : Running
SERVICETYPE property : Win32OwnProcess

See Also



Show:
© 2015 Microsoft