リスト ビュー (グループ別)

この例では、リストの行をグループに分割するリストビューを実装する方法を示します。 このリストビューには、Servicecontroller のプロパティが表示されます。 Displayproperty = Get Service コマンドレットによって返される Fullname オブジェクト。 リストビューのコンポーネントの詳細については、「 リストビューの作成」を参照してください。

この書式設定ファイルを読み込みます

  1. このトピックの「例」のセクションにある XML をテキストファイルにコピーします。

  2. テキスト ファイルを保存します。 ファイルに拡張子を追加して、 format.ps1xml 書式設定ファイルとして識別するようにしてください。

  3. Windows PowerShell を開き、次のコマンドを実行して、書式設定ファイルを現在のセッションに読み込み Update-formatdata -prependpath PathToFormattingFile ます。

警告

この書式設定ファイルは、Windows PowerShell の書式設定ファイルによって既に定義されているオブジェクトの表示を定義します。 prependPathコマンドレットを実行するときにパラメーターを使用する必要があります。このフォーマットファイルをモジュールとして読み込むことはできません。

対象

この書式設定ファイルは、次の XML 要素を示しています。

  • ビューの Name 要素。

  • ビューによって表示されるオブジェクトを定義する Viewselectedby 要素。

  • オブジェクトの新しいグループをどのように表示するかを定義する GroupBy 要素。

  • ビューによって表示されるプロパティを定義する ListControl 要素。

  • リストビューの行に表示される内容を定義する ListItem 要素。

  • 表示されるプロパティを定義する PropertyName 要素。

次の XML は、 Servicecontroller プロパティの値が変更されるたびに新しいグループを開始するリストビューを定義します。 各グループが開始されると、プロパティの新しい値を含むカスタムラベルが表示されます。

<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>

Servicecontroller を表示 Windows PowerShell 方法を次の例に示します。 Displayproperty = Fullnameオブジェクトこのフォーマットファイルが読み込まれた後。 グループラベルの前後に追加された空白行は、Windows PowerShell によって自動的に追加されます。

Get-Service f*
   New Service Status: Stopped

Name        : Fax
DisplayName : Fax
ServiceType : Win32OwnProcess

   New Service Status: Running

Name        : FCSAM
DisplayName : Microsoft Antimalware Service
ServiceType : Win32OwnProcess

   New Service Status: Stopped

Name        : fdPHost
DisplayName : Function Discovery Provider Host
ServiceType : Win32ShareProcess

   New Service Status: Running

Name        : FDResPub
DisplayName : Function Discovery Resource Publication
ServiceType : Win32ShareProcess

Name        : FontCache
DisplayName : Windows Font Cache Service
ServiceType : Win32ShareProcess

   New Service Status: Stopped

Name        : FontCache3.0.0.0
DisplayName : Windows Presentation Foundation Font Cache 3.0.0.0
ServiceType : Win32OwnProcess

   New Service Status: Running

Name        : FSysAgent
DisplayName : Microsoft Forefront System Agent
ServiceType : Win32OwnProcess

Name        : FwcAgent
DisplayName : Firewall Client Agent
ServiceType : Win32OwnProcess

参照

書式設定ファイルの例

PowerShell 書式設定ファイルを記述する