ok, I have googled this and I've used this very site and I'm still struggling with finding machines in AD that have not been active for 60 days. I have this code which almost works.
$pc=Get-ADComputer-Filter*-SearchBase"ou=All_Machines,dc=acme,dc=org" | Select name, pwdLastSet
$OlderThan='30'
$TargetOU="ou=Disabled Computers,dc=acme,dc=org"
$now=Get-Date
$agedate= (Get-Date).AddDays(-$OlderThan)
$agedate
foreach($Computerin$pc) {
if ($Computer.pwdLastSet-lt$OlderThan) {write-host"this is an old machine"}}
The problem is this. Even if I change $olderthan = '1' it still writes "this is an old machines" for Every machines in my OU.
How do you find only machines that have not been active?