PowerShell 7.3 - Difficulty Filtering Active Directory Users Based on Last Logon Time
I'm maintaining legacy code that I'm learning this framework and I'm testing a new approach and I've been struggling with this for a few days now and could really use some help. I'm trying to filter users from Active Directory based on their last logon time using PowerShell 7.3. Specifically, I want to retrieve users who have not logged in for the past 90 days. I used the `Get-ADUser` cmdlet, but I keep running into issues with the date comparison. My current approach is as follows: ```powershell $daysInactive = 90 $cutoffDate = (Get-Date).AddDays(-$daysInactive) $users = Get-ADUser -Filter * -Property LastLogonTimeStamp | Where-Object { [DateTime]::FromFileTime($_.LastLogonTimeStamp) -lt $cutoffDate } $users | Select-Object Name, LastLogonTimeStamp ``` When I run this code, I receive an empty array despite there being users who should match the criteria. I confirmed that the `LastLogonTimeStamp` property is populated for the users in question. I checked the format of `LastLogonTimeStamp`, and it appears to be in the correct format since it's being converted with `FromFileTime` correctly. The scenario seems to stem from the comparison itself. Additionally, I'm wondering if there is a better way to handle the connection to the Active Directory, considering performance for large organizations. Any help with this filtering scenario would be greatly appreciated, especially any insights into ensuring the comparisons are done correctly or if there are alternative methods to achieve the same result. My development environment is Ubuntu. Thanks in advance! I'd be grateful for any help. For context: I'm using Powershell on Linux. What would be the recommended way to handle this?