清單檢視 (GroupBy)

這個範例示範如何執行清單視圖,將清單中的資料列分隔成群組。 此清單視圖會顯示 System.serviceprocess.dll 的屬性 。 Servicecontroller?Displayproperty = 取得服務 Cmdlet 所傳回的 Fullname 物件。 如需清單視圖元件的詳細資訊,請參閱 建立清單視圖

載入此格式設定檔案

  1. 將本主題的範例一節中的 XML 複製到文字檔。

  2. 儲存文字檔案。 請務必將副檔名新增 format.ps1xml 至檔案,以將它識別為格式化檔案。

  3. 開啟 Windows PowerShell,然後執行下列命令,將格式化檔案載入目前的會話: Update-formatdata -prependpath PathToFormattingFile

警告

此格式化檔案會定義已由 Windows PowerShell 格式設定檔案定義之物件的顯示。 prependPath當您執行 Cmdlet 時,您必須使用參數,而且無法將此格式化檔案載入為模組。

示範

此格式化檔案示範下列 XML 元素:

範例

下列 XML 會定義每次 System.serviceprocess.dll 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>

下列範例顯示 Windows PowerShell 如何顯示system.serviceprocess.dll. Servicecontroller?在載入此格式檔案之後,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 格式設定檔案