I wrote a query that will find all acounts created more than 30 days ago that have Never logged in or logged in more that 60 days ago. I used Powershell v2 but the Quest AD module. Here's the query (reformatted for the reader)
Get-QADuser -searchroot "corp.net/user accounts/users/OurOU" | where
{
($_.whencreated -lt ((get-date).adddays(-30)) )
-and
(
( $_.lastLogonTimestamp -like "Never")
-or
($_.lastLogonTimestamp -lt ((get-date).adddays(-60))
)
}
When it runs, accounts that have never logged in are listed correctly, account that have been logged in, generate an error:
"Bad argument to operator "-lt" : Cannot compare "Monday, June 16 2010" because it is not iComparible"
(The error is pointing to the last line of code above)
since Monday, June 16 2010 is date-looking, I would expect it to fail in the comparison to Never, but it fails in comparison to another date.
What gives? How do I fix this?
Thanks
\\Greg