清單檢視 (基本)
這個範例示範如何執行顯示 System.serviceprocess.dll 的基本欄表視圖 。 Servicecontroller?Displayproperty = 取得服務 Cmdlet 所傳回的 Fullname 物件。 如需清單視圖元件的詳細資訊,請參閱 建立清單視圖。
載入此格式設定檔案
將本主題的範例一節中的 XML 複製到文字檔。
儲存文字檔案。 請務必將副檔名新增
format.ps1xml
至檔案,以將它識別為格式化檔案。開啟 Windows PowerShell,然後執行下列命令,將格式化檔案載入目前的會話:
Update-formatdata -prependpath PathToFormattingFile
。
警告
此格式化檔案會定義已由 Windows PowerShell 格式設定檔案定義之物件的顯示。 prependPath
當您執行 Cmdlet 時,您必須使用參數,而且無法將此格式化檔案載入為模組。
示範
此格式化檔案示範下列 XML 元素:
視圖的 名稱 元素。
ViewSelectedBy元素,定義視圖要顯示的物件。
ListControl元素,定義視圖顯示的屬性。
專案 清單元素, 定義清單視圖的資料列中顯示的內容。
定義要顯示之屬性的 PropertyName 元素。
範例
下列 XML 定義的清單視圖會顯示 System.serviceprocess.dll Servicecontroller 的四個屬性。 Displayproperty = Fullname 物件。 在每個資料列中,屬性的名稱後面會顯示內容的值。
<Configuration>
<View>
<Name>System.ServiceProcess.ServiceController</Name>
<ViewSelectedBy>
<TypeName>System.ServiceProcess.ServiceController</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>DisplayName</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Status</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ServiceType</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</Configuration>
下列範例顯示 Windows PowerShell 如何顯示system.serviceprocess.dll. Servicecontroller?在載入此格式檔案之後,Displayproperty = Fullname 物件。
Get-Service f*
Name : Fax
DisplayName : Fax
Status : Stopped
ServiceType : Win32OwnProcess
Name : FCSAM
DisplayName : Microsoft Antimalware Service
Status : Running
ServiceType : Win32OwnProcess
Name : fdPHost
DisplayName : Function Discovery Provider Host
Status : Stopped
ServiceType : Win32ShareProcess
Name : FDResPub
DisplayName : Function Discovery Resource Publication
Status : Running
ServiceType : Win32ShareProcess
Name : FontCache
DisplayName : Windows Font Cache Service
Status : Running
ServiceType : Win32ShareProcess
Name : FontCache3.0.0.0
DisplayName : Windows Presentation Foundation Font Cache 3.0.0.0
Status : Stopped
ServiceType : Win32OwnProcess
Name : FSysAgent
DisplayName : Microsoft Forefront System Agent
Status : Running
ServiceType : Win32OwnProcess
Name : FwcAgent
DisplayName : Firewall Client Agent
Status : Running
ServiceType : Win32OwnProcess
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應