我创建了一个课程:
Class Group {
[Guid]$Id
[String]$DisplayName
[String[]]$Schemas
}
和一个Test.format.ps1xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<SelectionSets>
</SelectionSets>
<Controls>
</Controls>
<ViewDefinitions>
<View>
<Name>Group</Name>
<ViewSelectedBy>
<TypeName>Group</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<PropertyName>DisplayName</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
我将格式添加到当前的PowerShell实例:
Update-formatdata –prependpath "C:\Work\Test.format.ps1xml"
但是,当我创建一个Group实例时,格式没有被应用,我看到了该类的所有成员。
E.g。
$group = New-Object Group
$group.Id = [Guid]::NewGuid()
$group.DisplayName = 'Name'
$group.Schemas = @('schema1', 'schema2')
$group
产生
PS C:\Work> $group
Id : e2b6ccff-e72d-4494-8242-975618889c9c
DisplayName : Name
Schemas : {schema1, schema2}
我预计不会看到Schemas系列。
答案 0 :(得分:0)
我怀疑架构定义不合适,你可以查看这个ps1xml:
<Configuration>
<ViewDefinitions>
<View>
<Name>Group</Name>
<ViewSelectedBy>
<TypeName>Group</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>33</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>12</Width>
<Alignment>Center</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>displayname</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>