如何通过Powershell查询上次登录日期
我正在尝试查询上次登录到30天前的计算机如何通过Powershell查询上次登录日期,powershell,active-directory,Powershell,Active Directory,我正在尝试查询上次登录到30天前的计算机 清除主机 $Threshold=(获取日期).AddDays(-30) $NotInUse=获取ADComputer-过滤器*-属性LastLogonDate |其中{ $\.name-如“*LN-T48*”-和$\.lastLogonData-gt$阈值 } $NotInUse |选择名称,LastLogonDate-详细 使用-lt 使用过滤器更快: $Threshold = (Get-Date).AddDays(-30) $NotInUse =
清除主机
$Threshold=(获取日期).AddDays(-30)
$NotInUse=获取ADComputer-过滤器*-属性LastLogonDate |其中{
$\.name-如“*LN-T48*”-和$\.lastLogonData-gt$阈值
}
$NotInUse |选择名称,LastLogonDate-详细
使用-lt
使用过滤器更快:
$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
我得到的结果似乎是几天前的,而不是30天前的