Hi,
I have the following script that is supposed to search AD for all user accounts that haven't logged into the domain in more than 90 days. I first did not have the where-object clause because I didn't realize the search-adaccount would provide results back of users that have never logged in, but were created less than 90 days ago. So I tried to incorporate the logic to not include user accounts that were created in the last 90 days.
#requires -version 4
#This script creates a file of accounts that have not been logged into in the past 90 days, excluding accounts that have been created within the past 90 days since the -AccountInactive option does not factor for the whenCreated property of an AD object
$DateThreshold = ((Get-Date).AddDays(-90))
$ReportDate = Get-Date -Format yyyy-MM-dd
#Create a folder according to the current date to be used for storing the report
New-Item -Path ".\$ReportDate" -ItemType Directory
$InactiveUsers = Search-ADAccount -UsersOnly -AccountInactive -TimeSpan "90" -SearchBase "OU=XXXX,DC=XXXX,DC=XXXX,DC=XXXX" | Where-Object {$_.whenCreated -gt $DateThreshold} | Export-Csv ".\$ReportDate\Inactive90_$ReportDate.csv"
However, I can't ever get the whenCreated field to populate with data. What gives?