将日期列表与 MAX 日期进行比较

Comparing Dates List with MAX Date

我有一个带最大日期的输出 $a 和 $b,如下所示: 我想比较包含日期的 $a 和 $b 并得到结果。 $a 和 $b 每天都会变化。目标是每天在 MAX Date 之后获取所有内容。 MAX 日期每天都会随着新数据的加载而变化,$a 每天都会变化。

$a 是这样导出的:

$access_token ="Access_Token"

$URI =  "https://XXXXX"
$headers = @{“authorization” = “Bearer $access_token”} 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$result = Invoke-RestMethod -Uri $URI -Headers $headers -ContentType $ContentType |ConvertTo-Json
$a = $Result|ConvertFrom-Json| Select -ExpandProperty Forms
$a= 

id          date
--------    -----------
Person 1    01/02/2017 10:59:15
Person 2    02/03/2017 13:10:19
Person 3    04/05/2017 11:11:12
Person 4    10/10/2017 10:42:19
Person 5    10/10/2017 13:34:58
$b= 

MAX_Date
02/03/2017 13:10:19 
Desired results:

id          date
--------    -----------
Person 3    04/05/2017 11:11:12
Person 4    10/10/2017 10:42:19
Person 5    10/10/2017 13:34:58

正如 Mathias 所说,我们需要更多细节。但为了让您抢先一步,以下方法会起作用:

$A = @(
    [PSCustomObject]@{
        id   = 'Person 1'
        date = [DateTime]'01/02/2017 10:59:15'
    }
    [PSCustomObject]@{
        id   = 'Person 2'
        date = [DateTime]'02/03/2017 13:10:19'
    }
    [PSCustomObject]@{
        id   = 'Person 3'
        date = [DateTime]'04/05/2017 11:11:12'
    }
    [PSCustomObject]@{
        id   = 'Person 4'
        date = [DateTime]'10/10/2017 10:42:19'
    }
    [PSCustomObject]@{
        id   = 'Person 5'
        date = [DateTime]'10/10/2017 13:34:58'
    }
)

$B = @{
    MAX_Date = [DateTime]'02/03/2017 13:10:19 '
}

$A | Where-Object { $_.date -gt $B.MAX_Date } | Sort-Object id
#First we need to cast this string into a date so it will compare properly.
$Max_Date = Get-Date $b.MAX_Date
#Then we need an array to store the objects that we want to keep
$Dates_to_Keep = ()
#Now we can iterate through the array and check the date on each object.
Foreach ($person in $a){
    #Again, casting this string as a date for accurate comparison. 
    $date = Get-Date $person.date
    If ($date -ge $Max_Date){
         $Dates_to_Keep = $Dates_to_Keep + $person
    }
}
Write-Host $Dates_to_Keep

这是我根据 OP 中提供的信息做出的最佳猜测。