从在PowerShell中每个对象组数组获取最新日期 [英] Get latest dates from an array per object group in Powershell

查看:137
本文介绍了从在PowerShell中每个对象组数组获取最新日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组的 $数据的:

  PS> $数据
基准用户计算机
----- --------- --------
2013年10月6日13时10分56秒geb1@TESTDOMAIN.COM DC1 $
2013年10月6日13时09分25秒geb2@TESTDOMAIN.COM DC2 $
2013年10月6日10点05分13秒geb2@TESTDOMAIN.COM DC2 $
2013年7月6日16时32分47秒geb1@TESTDOMAIN.COM DC1 $

我想从$ data数组的最新日期这样的每台计算机:

  PS> $结果
基准用户计算机
----- --------- --------
2013年10月6日13时10分56秒geb1@TESTDOMAIN.COM DC1 $
2013年10月6日13时09分25秒geb2@TESTDOMAIN.COM DC2 $

我真的无法得到这样的结果。你能帮我在这?


解决方案

  $数据|的foreach对象{$ _基准= [DATETIME] $ _基准。; $ _} |
集团目标机|
。的foreach对象{$ _集团|排序对象基准|选择对象 - 最后1}

I have an array $data :

PS> $data
Datum                  User                   Computer                                      
-----                  ---------              --------                                      
10/06/2013 13:10:56    geb1@TESTDOMAIN.COM    DC1$                                          
10/06/2013 13:09:25    geb2@TESTDOMAIN.COM    DC2$                                          
10/06/2013 10:05:13    geb2@TESTDOMAIN.COM    DC2$                                          
7/06/2013 16:32:47     geb1@TESTDOMAIN.COM    DC1$    

I want to get the latest dates from the $data array for each computer like this:

PS> $result
Datum                  User                   Computer                                      
-----                  ---------              --------                                      
10/06/2013 13:10:56    geb1@TESTDOMAIN.COM    DC1$                                          
10/06/2013 13:09:25    geb2@TESTDOMAIN.COM    DC2$                                          

I really couldn't get this result. Could you please help me on this?

解决方案

$data | Foreach-Object {$_.Datum = [DateTime]$_.Datum; $_} | 
Group-Object Computer | 
Foreach-Object {$_.Group | Sort-Object Datum | Select-Object -Last 1}

这篇关于从在PowerShell中每个对象组数组获取最新日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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