使用PowerShell的格式表

时间:2015-05-12 13:32:17

标签: powershell sharepoint sharepoint-2010 powershell-v3.0

假设Atom feed的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属性相关联的内容的正确语法是什么?

1 个答案:

答案 0 :(得分:0)

你不必使用标签。

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