使用 PowerShell 的格式显示元素的属性-Table

Display element's attribute using PowerShell's Format-Table

假设 Atom 提要的 XML:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed ... >
  <title type="text">Attachments</title>
  <id>http://server/list/_vti_bin/listdata.svc/list(1234)/Attachments/</id>
  <updated>2015-05-12T13:00:05Z</updated>
  <link rel="self" title="Attachments" href="Attachments" />
  <entry>
    <id>...</id>
    <title type="text">spreadsheet.xlsx</title>
    <updated>2015-05-12T13:00:05Z</updated>
    <author>
      <name />
    </author>
    <link ... />
    <link ... />
    <category term="Microsoft.SharePoint.DataService.AttachmentsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" src="http://server/list/Attachments/1234/spreadsheet.xlsx" />
    <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
      <d:EntitySet>TheList</d:EntitySet>
      <d:ItemId m:type="Edm.Int32">1234</d:ItemId>
      <d:Name>spreadsheet.xlsx</d:Name>
    </m:properties>
  </entry>

不幸的是,$_.Content.'#type'$_.Content.'#src' 没有识别属性:

$webRequest = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials
[xml]$xml = $webRequest.Content

$properties = $xml.feed.entry
$properties | Format-Table -Property `
  @{Label="Title"; Expression={$_.Title.'#text'}; Width=50},
  @{Label="Url"; Expression={$_.Content.'#src'}; Width=20},
  @{Label="ContentType"; Expression={$_.Content.'#type'}; Width=12}

获取与 content.typecontent.src 属性关联的内容的正确语法是什么?

您不必使用主题标签。

PS>$xml.feed.entry.content.type                                      
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet