Reputation: 47
I'm trying to query machines which were last logged on to 30 days ago
Clear-Host
$Threshold = (Get-Date).AddDays(-30)
$NotInUse = Get-ADComputer -Filter * -Properties LastLogonDate | Where {
$_.name -Like "*LN-T48*" -and $_.LastLogonDate -gt $Threshold
}
$NotInUse | select Name, LastLogonDate -Verbose
Upvotes: 1
Views: 478
Reputation: 3923
Use -lt
Using the filter is quicker:
$Threshold = (Get-Date).AddDays(-30)
$NotInUse = Get-ADComputer -Filter {LastLogonDate -lt $Threshold} -Properties LastLogonDate |
Where { $_.name -Like "*LN-T48*"}
$NotInUse | select Name, LastLogonDate -Verbose | sort LastLogonDate
Upvotes: 1