Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

filter Published Date of modules in Powershell

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading