使用PowerShell命令查询Active Directory中长时间没有登录计算机帐户。以180天为例:
# This PowerShell Command will query Active Directory and return the computer accounts which have not logged for the past
# 180 days. You can easily change the number of days from 180 to any number of your choosing.
# lastLogonDate is a Human Readable conversion of the lastLogonTimeStamp
# The 180 is the number of days from today since the last logon.
$then = (Get-Date).AddDays(-180)
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | FT Name,lastLogonDate
# If you would like to Disable these computer accounts, uncomment the following line:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Set-ADComputer -Enabled $false
# If you would like to Remove these computer accounts, uncomment the following line:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Remove-ADComputer
使用PowerShell命令查询Active Directory中长时间没有登录计算机帐户。以180天为例:
# This PowerShell Command will query Active Directory and return the computer accounts which have not logged for the past
# 180 days. You can easily change the number of days from 180 to any number of your choosing.
# lastLogonDate is a Human Readable conversion of the lastLogonTimeStamp
# The 180 is the number of days from today since the last logon.
$then = (Get-Date).AddDays(-180)
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | FT Name,lastLogonDate
# If you would like to Disable these computer accounts, uncomment the following line:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Set-ADComputer -Enabled $false
# If you would like to Remove these computer accounts, uncomment the following line:
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $then} | Remove-ADComputer