Powershell expiry date comparison

Hello Experts,

 

Hope you all are safe and well !!

I am running a script that gives me Azure AD apps with its secret end date property. The property name which gives me all details in Azure AD is “PasswordCredentials” and I am using get-azureadapplication cmdlet.

What is the best way to check If the app has end date value within a month and filter on it, I tried where-object with get-date.adddays(30) and tried to compare with -lt operators.

Appreciate your support here.

 

Thanks

To which property did your where clause try to filter against? You should post the code you tried, regardless of if it worked. That gives us a better starting point.

Thanks for the reply, I am trying to use the below-mentioned script to fetch expiry date for secret key although I would like to see If I can get only those application’s secrets which is getting expired within a month.

 

https://gist.github.com/svarukala/64ade1ca6f73a9d18236582e8770d1d4

I got it working but not sure If this is the best way as I am still learning PowerShell

 

Get-AzureADApplication -all $true | where {$.passwordcredentials.enddate -notlike “” -and $.passwordcredentials.enddate -LE ((get-date).AddDays(30))} | select @{Name=”DisplayName”; Expression={$.displayname}}, @{Name=”EndDate”; Expression={$.passwordcredentials.enddate}}