如何在PowerShell中显示带.ps1xml文件的嵌套集合 [英] How to display a nested collection with .ps1xml file in powershell

查看:201
本文介绍了如何在PowerShell中显示带.ps1xml文件的嵌套集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public class Department 
{
public string名称{get;组; }
public string Manager {get;组; }
public Employee [] Employees {get;组; }
}

public class Employee
{
public string Name {get; set;}
public string Speciallity {get;组;如何创建自定义的.ps1xml文件,让我显示




$ b

code>部门如下:


 部门:测试人员
经理:PH老板

名称Speciallity
---------- ------------------------- ----
某些员工.Net
另一个员工BizTalk
另一个PowerShell
... ...


部门:开发人员
经理:Wally

名称Speciallity
---------- ------------------ -----------
某些员工.Net
另一个员工BizTalk
另一个PowerShell
... ...



$ b $主要的问题是我如何定义一个< ;根据 TableControl 部门选择的View> Department.Employees



我可以显示 Employee (s)完全正确使用查看

 < View> 
<名称>员工< /名称>
< ViewSelectedBy>
< TypeName> Employee< / TypeName>
< / ViewSelectedBy>
< TableControl>
< TableHeaders>
< TableColumnHeader>
<标签>名称< /标签>
<宽度> 30< /宽度>
< / TableColumnHeader>
< TableColumnHeader>
<标签> Speciallity< /标签>
<宽度> 50< /宽度>
< / TableColumnHeader>
< / TableHeaders>
< TableRowEntries>
< TableRowEntry>
< Wrap />
< TableColumnItems>
< TableColumnItem>
< PropertyName>名称< / PropertyName>
< / TableColumnItem>
< TableColumnItem>
< PropertyName> Speciallity< / PropertyName>
< / TableColumnItem>
< / TableColumnItems>
< / TableRowEntry>
< / TableRowEntries>
< / TableControl>
< / View>

我可以使用列表格式来格式化部门:

 <查看> 
<名称> TestResultSet< /名称>
< ViewSelectedBy>
< TypeName>部门< / TypeName>
< / ViewSelectedBy>
< ListControl>
< ListEntries>
< ListEntry>
< ListItems>
< ListItem>
<标签>部门< /标签>
< PropertyName>名称< / PropertyName>
< / ListItem>
< ListItem>
< PropertyName>经理< / PropertyName>
< / ListItem>
< / ListItems>
< / ListEntry>
< / ListEntries>
< / ListControl>
< / View>

但是,如何在部门之后添加员工表?

$ b $我认为你需要使用< GroupBy> ...< / GroupBy < Control>< CustomControl> ...< / CustomControl>< / Control> $ b

查看 ps1xml格式文件的DiscUtils模块,还没有机会自己玩它,但它可能会把你放在正确的道路。



另请参阅 help about_Format.ps1xml 它有一些信息,虽然对于某些方面的例子有点亮。


I have a hierarchical object structure like this:

public class Department
{
    public string Name { get; set; }
    public string Manager { get; set; }
    public Employee[] Employees { get; set; }
}

public class Employee
{
    public string Name { get; set;}
    public string Speciallity { get; set; }
}

How can i create a custom .ps1xml file that will let me display Department(s) as follows:

    Department : Testers
    Manager    : P.H. Boss

Name                       Speciallity
----------                 -----------------------------
Some Employee              .Net
Another Employee           BizTalk
Yet Another                PowerShell
...                        ...


    Department : Developers
    Manager    : Wally

Name                       Speciallity
----------                 -----------------------------
Some Employee              .Net
Another Employee           BizTalk
Yet Another                PowerShell
...                        ...

The main problem i'm having is how i can define a <View> item that is selected for a Department, that is based on a TableControl, but which displays the Department.Employees in the table control.

I can display Employee(s) perfectly fine using a View:

<View>
    <Name>Employee</Name>
    <ViewSelectedBy>
        <TypeName>Employee</TypeName>
    </ViewSelectedBy>
   <TableControl>
        <TableHeaders>
            <TableColumnHeader>
                <Label>Name</Label>
                <Width>30</Width>
            </TableColumnHeader>
            <TableColumnHeader>
                <Label>Speciallity</Label>
                <Width>50</Width>
            </TableColumnHeader>
        </TableHeaders>
        <TableRowEntries>
            <TableRowEntry>
                <Wrap/>
                <TableColumnItems>
                    <TableColumnItem>
                        <PropertyName>Name</PropertyName>
                    </TableColumnItem>
                    <TableColumnItem>
                        <PropertyName>Speciallity</PropertyName>
                    </TableColumnItem>
                </TableColumnItems>
            </TableRowEntry>
        </TableRowEntries>
    </TableControl>
</View>

And i can format departments using a list format:

<View>
    <Name>TestResultSet</Name>
    <ViewSelectedBy>
        <TypeName>Department</TypeName>
    </ViewSelectedBy>
    <ListControl>
        <ListEntries>
            <ListEntry>
                <ListItems>
                    <ListItem>
                        <Label>Department</Label>
                        <PropertyName>Name</PropertyName>
                    </ListItem>
                    <ListItem>
                        <PropertyName>Manager</PropertyName>
                    </ListItem>
                </ListItems>
            </ListEntry>
        </ListEntries>
    </ListControl>
</View>

But how do i add a table of the employees after the department?

解决方案

I think you need to make use of <GroupBy>...</GroupBy and also <Control><CustomControl>...</CustomControl></Control>

Take a look at this ps1xml format file for DiscUtils module, haven't had the chance to play with it myself yet but it may put you on the right path.

See also the help about_Format.ps1xml which has some info, though a little light on examples for some aspects.

这篇关于如何在PowerShell中显示带.ps1xml文件的嵌套集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆