Find user accounts that have had no activity in over x amount of days with powershell

Hello,

I am attempting to utilize powershell with ARS to perform some activity cleanup. Basically what we are looking to do is identify all of the user accounts in our domain(s) that have not been logged into in say, 30 days or more. The exact time is going to be variable depending on the domain.

While I can get a list of all of the users in the various OUs, how could I construct a script that can just return those particular objects that meet the aforementioned activity criteria and export that to a CSV file?