I have an array piped into PowerShell. Trying to select what matches today through the next 3 weeks.
1/4/2023 First Last
1/11/2023 First Last
1/19/2023 First Last
1/25/2023 First Last
2/1/2023 First Last
2/8/2023 First Last
2/15/2023 First Last
2/22/2023 First Last
3/1/2023 First Last
3/8/2023 First Last
Expected results would be:
1/19/2023 First Last
1/25/2023 First Last
2/1/2023 First Last
2/8/2023 First Last
Was trying to modify this to get results, but not getting what I need.
$referenceDate = (Get-Date).AddDays(21)
Get-Content -Path 'Dates.ini' |
Where-Object { $_ -match '^(\d{2}/\d{2}/\d{4})' } |
Where-Object { [datetime]::ParseExact($matches[1], 'MM/dd/yyyy', $null) -gt $referenceTime } |
ForEach-Object {
$_
#DO SOMETHING.. For demo just output the line(s) that matched
}
My PowerShell kung foo is not strong, and would be very grateful for the answer...
Listed in details. PowerShell version is default for Server 2019.