I am trying to list all accounts that are not logged in beyond 6 months.
This is my first time that I really use powershell, and I'm just editing other people's scripts at this point to fit my own needs.
I want to divide the search into two lists: only computers and only users.
Code for computers in six months.
Search-ADAccount -accountinactive -computersonly | where {$_.lastlogondate -lt (get-date).addmonths(-6)} | FT Name,LastLogonDate
Code for users over six months old.
Search-ADAccount -accountinactive -usersonly | where {$_.lastlogondate -lt (get-date).addmonths(-6)} | FT Name,LastLogonDate
However, they do not work and just spit out all the accounts. I also noticed that a change of -6 does not really affect any number. Suggestions?
source
share