此示例演示如何实现显示 System.ServiceProcess.ServiceController get-Service cmdlet 返回的对象的基本列表视图。 有关列表视图组件的详细信息,请参阅 创建列表视图。
加载此格式设置文件
将本主题的“示例”部分中的 XML 复制到文本文件中。
保存该文本文件。 请务必将
format.ps1xml
扩展名添加到文件,以将其标识为格式化文件。打开 Windows PowerShell,并运行以下命令将格式化文件加载到当前会话中:
Update-FormatData -PrependPath PathToFormattingFile
。
警告
此格式设置文件定义已由 Windows PowerShell 格式化文件定义的对象的显示。 运行 cmdlet 时,必须使用 PrependPath
参数,并且无法将此格式文件加载为模块。
演示
此格式设置文件演示了以下 XML 元素:
视图的 Name 元素。
ViewSelectedBy 元素,用于定义视图显示的对象。
ListControl 元素,用于定义视图显示的属性。
ListItem 元素,用于定义列表视图行中显示的内容。
PropertyName 元素,用于定义显示哪个属性。
示例
以下 XML 定义一个列表视图,该视图显示 System.ServiceProcess.ServiceController 对象的四个属性。 在每个行中,将显示属性的名称后跟属性的值。
<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.ServiceController 对象。
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