清單檢視 (標籤)
此範例示範如何執行清單視圖,以針對清單中的每個資料列顯示自訂標籤。 此清單視圖會顯示 System.serviceprocess.dll 的屬性 。 Servicecontroller?Displayproperty = 取得服務 Cmdlet 所傳回的 Fullname 物件。 如需清單視圖元件的詳細資訊,請參閱 建立清單視圖。
載入此格式設定檔案
將本主題的範例一節中的 XML 複製到文字檔。
儲存文字檔案。 請務必將副檔名新增
format.ps1xml
至檔案,以將它識別為格式化檔案。開啟 Windows PowerShell,然後執行下列命令,將格式化檔案載入目前的會話:
Update-formatdata -prependpath PathToFormattingFile
。
警告
此格式化檔案會定義已由 Windows PowerShell 格式設定檔案定義之物件的顯示。
prependPath
當您執行 Cmdlet 時,您必須使用參數,而且無法將此格式化檔案載入為模組。
示範
此格式化檔案示範下列 XML 元素:
視圖的 名稱 元素。
ViewSelectedBy元素,定義視圖要顯示的物件。
ListControl元素,定義視圖顯示的屬性。
專案 清單元素, 定義清單視圖的資料列中顯示的內容。
Label元素,定義清單視圖的資料列中顯示的內容。
定義要顯示之屬性的 PropertyName 元素。
範例
下列 XML 定義的清單視圖會在每個資料列中顯示自訂標籤。 在此情況下,標籤會包含每個字母大寫的屬性名稱和 "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>
下列範例顯示 Windows PowerShell 如何顯示system.serviceprocess.dll. Servicecontroller?在載入此格式檔案之後,Displayproperty = Fullname 物件。
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
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應