Home > Software design >  filter Published Date of modules in Powershell
filter Published Date of modules in Powershell

Time:04-22

I'm trying to filter powershell modules between two dates but my outcome is empty, this is my code:

$startDate = (Get-Date)
$endDate = (Get-Date).AddYears(-1)

Find-Module Microsoft*  | Select-Object -Property Name,  PublishedDate |  Where-Object {
      ( $_.PublishedDate -ge $startDate ) -and 
      ( $_.PublishedDate -lt $endDate ) }

is it maybe because of my culture settings ? my culture settings are:

2067             nl-BE            Dutch (Belgium)
PS C:\WINDOWS\system32> get-date
donderdag 21 april 2022 20:47:35

a few of my search results when I do a find-module

Find-Module Microsoft*  | Select-Object -Property Name,  PublishedDate


MicrosoftTeams                                     13/04/2022 14:56:54
Microsoft.Graph.Intune                             11/07/2019 5:12:40
Microsoft.PowerApps.Administration.PowerShell      11/04/2022 15:08:14
Microsoft.Graph.Authentication                     14/04/2022 0:23:03

CodePudding user response:

Your logic is backwards, try this:

$startDate = (Get-Date).AddYears(-1)
$endDate = (Get-Date)

Find-Module Microsoft*  | Select-Object -Property Name,  PublishedDate |  Where-Object {
      ( $_.PublishedDate -ge $startDate ) -and 
      ( $_.PublishedDate -lt $endDate ) }

You were filtering on anything with a PublishedDate after today, and older than today minus 1 year.

  • Related