PowerShell – Filter a list Computers by LastLogon Date

I needed a script to filter a list of computers by the number of days since the computer was last logged onto.  This is my solution to that.  When supplied a list of computers, this will return the ones that have been Active (Logged On) within the Last X amount of days.  Where X is supplied as $DaysSinceLastLogon.  I’ve populated the PowerShell Comment Doc, so check out the Examples supplied in there for usage.

Hope it helps others out there.  Just add the function to your PowerShell Profile or as a Functions in a script to make it available!

Leave a Reply

Your email address will not be published. Required fields are marked *