格式化Powershell列表查询
我正在使用caml查询检索列表项,使用:格式化Powershell列表查询,powershell,Powershell,我正在使用caml查询检索列表项,使用: $list = $web.Lists["My List"] $items = $list.GetItems($query) 我需要以可读的格式输出这些数据,比如一个表。当我使用: $items | Format-Table 我得到一张桌子,它是用我不知道的东西搭建的。这绝对不是清单上的项目。以下是输出: ListItems Parent List ---------
$list = $web.Lists["My List"]
$items = $list.GetItems($query)
我需要以可读的格式输出这些数据,比如一个表。当我使用:
$items | Format-Table
我得到一张桌子,它是用我不知道的东西搭建的。这绝对不是清单上的项目。以下是输出:
ListItems Parent List
--------- -----------
{Title of List Item 1, Title of List Item 2, ...} My List
{Title of List Item 1, Title of List Item 2, ...} My List
{Title of List Item 1, Title of List Item 2, ...} My List
如果我使用foreach循环来输出items中的每个项,我会得到正确的数据,但在将其格式化到表中时遇到问题。以下是我的做法:
foreach($item in $items) {
Write-Host $item["Title"] ---- $item["Author"] ---- $item["Category"]
}
哪些产出:
Test Title 1 ---- Hemingway ---- Best Seller
The Title of Number 2 ---- Stein ---- Horror
Three ---- Shakespeare ---- Tragedy
不太可读。如何访问方法1中的正确数据,或将方法2格式化为表格?为每个项目创建一个自定义表格,并将其传送到
格式化表格
:
$items | Foreach-Object{
New-Object PSObject -Property @{
Title = $_["Title"]
Author = $_["Author"]
Category = $_["Category"]
}
} | Format-Table
我没有尝试过,但看看这是否有帮助…$items.ListItems | Format table的结果是什么:$items | Get Member-MemberType属性
$items | Get Member
和$items[0]的输出是什么。ListItems | Get Member