此示例演示如何实现显示 System.ServiceProcess.ServiceController 组的宽视图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