Basically, it outputs lastlogontimestamp and I want it to output it as the number of days since the last logon. Any suggestions? I appreciate the help!
On a side note, you’re filtering for $_.LastLogonTimestamp -eq $null , which doesn’t make much sense with the rest of the code. Did you mean to do -ne $null ? I haven’t used the Quest AD cmdlets, but I assume that they have something like -Filter or -LdapFilter arguments; you’d have better performance by using that instead of Where-Object.
will only pass users that don’t have a lastlogontimestamp set
where { $_.whencreated -le $60 }
I’m assuming $60 is holding a date 60 days in the past so you are picking accounts that were created more than 60 days ago
If I understand what you are trying to do - you want a list of all users who have logged on and you want to see the number of days since they logged on
Something like this should work for you
Get-QADUser -IncludedProperties lastlogontimestamp | where {$.lastlogontimestamp -ne $null} |
select samaccountname, name, @{N=‘daysSinceLogon’; E={ ( (get-date) - $($.lastlogontimestamp) ).days } }, whencreated
You need to subtract the lastlogontimestamp from today to get a timespan - the Days property gives you how many days ago the logon occurred
Hi sorry for the confusion, this was just the second half of the script that cleaned up user accounts that had never logged on. Thanks for the help Richard though! That one seems to be working.