這個範例示範如何實作寬檢視,以顯示 System.ServiceProcess.ServiceControll er 群組 Get-Service Cmdlet 所傳回的物件。 如需寬檢視元件的詳細資訊,請參閱 建立寬檢視。
載入此格式檔案
將本主題的範例區段的 XML 複製到文字檔中。
儲存文字檔。 請務必將
format.ps1xml擴展名新增至檔案,以將其識別為格式化檔案。開啟 Windows PowerShell,然後執行下列命令,將格式化檔案載入目前的工作階段:
Update-FormatData -PrependPath <Path to file>。警告
此格式化檔案會定義 Windows PowerShell 格式化檔案已經定義的物件顯示。 當您執行 Cmdlet 時,必須使用 PrependPath 參數,而且無法將此格式化檔案載入為模組。
演示
此格式化檔案示範下列 XML 元素:
檢視 Name 專案。
ViewSelectedBy 元素,定義檢視所顯示的物件。
GroupBy 元素,定義新群組的顯示時機。
WideItem 元素,定義檢視所顯示的屬性。
範例
下列 XML 會定義顯示物件群組的寬檢視。 當 system.ServiceProcess.ServiceController.ServiceType 屬性值變更時,就會啟動每個新的群組。
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>ServiceWideView</Name>
<ViewSelectedBy>
<TypeName>System.ServiceProcess.ServiceController</TypeName>
</ViewSelectedBy>
<GroupBy>
<Label>Service Type</Label>
<PropertyName>ServiceType</PropertyName>
</GroupBy>
<WideControl>
<WideEntries>
<WideEntry>
<WideItem>
<PropertyName>ServiceName</PropertyName>
</WideItem>
</WideEntry>
</WideEntries>
</WideControl>
</View>
</ViewDefinitions>
</Configuration>
下列範例示範 Windows PowerShell 如何顯示載入此格式檔案之後 System.ServiceProcess.ServiceController 物件。
Get-Service f*
Service Type: Win32OwnProcess
Fax FCSAM
Service Type: Win32ShareProcess
fdPHost FDResPub
FontCache
Service Type: Win32OwnProcess
FontCache3.0.0.0 FSysAgent
FwcAgent
另請參閱
格式化檔案 範例