如何在Powershell中分组和筛选Sharepoint webservice XML响应

如何在Powershell中分组和筛选Sharepoint webservice XML响应,powershell,sharepoint-2010,Powershell,Sharepoint 2010,我需要根据Sharepoint列表发送自动电子邮件。我能够检索响应,并有代码发送电子邮件。但是电子邮件正文需要是动态的,并且需要对响应日期进行分组。我正在考虑将服务响应转换为hashmap,并使用该hashmap发送目标电子邮件。以下是服务响应的示例: <rs:data ItemCount="10"> <z:row ows_Owner='1111@xxx.com' ows_Stories='Story1' ows_Program='Program1' />

我需要根据Sharepoint列表发送自动电子邮件。我能够检索响应,并有代码发送电子邮件。但是电子邮件正文需要是动态的,并且需要对响应日期进行分组。我正在考虑将服务响应转换为hashmap,并使用该hashmap发送目标电子邮件。以下是服务响应的示例:

  <rs:data ItemCount="10">
     <z:row ows_Owner='1111@xxx.com' ows_Stories='Story1' ows_Program='Program1' />
     <z:row ows_Owner='1111@xxx.com' ows_Stories='Story2' ows_Program='Program1' />
     <z:row ows_Owner='1111@xxx.com' ows_Stories='Story3' ows_Program='Program2' />
     <z:row ows_Owner='1111@xxx.com' ows_Stories='Story4' ows_Program='Program2' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story5' ows_Program='Program1' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story6' ows_Program='Program1' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story7' ows_Program='Program1' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story8' ows_Program='Program2' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story9' ows_Program='Program2' />
     <z:row ows_Owner='2222@xxx.com' ows_Stories='Story10' ows_Program='Program2' />
  </rs:data>
使用powershell对上述数据进行分组和迭代的最佳方式是什么,以发送一封邮件,邮件正文包含按“程序”分组的“故事”消息。例如:电子邮件发送至'1111@xxx.com'将消息正文设置为:

方案1

故事1 故事2 方案2

故事3 故事4 更新: 以下是更好地解释我的需求的伪代码-

select unique $owners from rs:row

foreach $owner in $owners
{     $messageBody =""
    foreach $program in rs:row where ows_owner=$owner
    {
        $messageBody += $program "<br />
        foreach $story in rs:row where ows_owner=$owner and ows_program=$program
        $messageBody += $story "<br />
     }
         sendmail $owner, $messageBody 
}    

只需编写代码即可在powershell中轻松实现这一点,特别是根据“所有者”和“程序”属性过滤数据

我将从节点创建自定义powershell对象,然后使用它们按程序进行分组:

[xml]$xml=获取内容“C:\path\to\input.xml” $nsm=新对象Xml.XmlNamespaceManager$Xml.NameTable $nsm.AddNamespace'rs','http://...'替换为正确的命名空间URI $xml.SelectSingleNode'//rs:data',$nsm | select-展开行|%{ 新对象-类型PSCustomObject-属性@{ Program=$\uu.ows\u程序 故事=$\uu0.ows\u故事 } }|组程序|选择名称,@{n='Stories';e={$\u.group.Story} 如果分组不是一个选项,您可以构建嵌套哈希表的数据结构,如下所示:

$data=@{} $xml.SelectSingleNode'//rs:data',$nsm | select-展开行|%{ 新对象-类型PSCustomObject-属性@{ 所有者=$\uu0.ows\u所有者 Program=$\uu.ows\u程序 故事=$\uu0.ows\u故事 } } | % { if-not$data.Contains$\所有者{ $data[$\.Owner]=@{$\.Program=@} }elseif-非$data[$\uU2.Owner]。包含$\uU3.Program{ $data[$\.Owner][$\.Program]=@ } $data[$\.Owner][$\.Program]+=$\.Story }
谢谢回复@Ansgar。虽然您的解决方案可以按“程序”对“故事”进行分组,但我们也需要按“所有者”对它们进行分组,以便我们可以发送包含与特定所有者相关的程序和故事的电子邮件。如果有帮助的话,这就是我在algotrithm方面的想法——我将用我认为可以作为解决方案的伪代码更新我的原始帖子。感谢@Ansgar提供更新的解决方案。这很好用。通过枚举$data,我得到了预期的结果。