我一直在使用下面的命令来输出最后一个已知的login的计算机设置为退役。 该脚本的作品,但只在当前login的DC。 我怎样才能让它循环通过networking中的所有区议会。
Get-Content C:\ noresponse.csv | Foreach-Object {Get-ADComputer $ _ -Properties LastLogonDate} | SortLastLogonDate | FT名称,LastLogonDate -Autosize | Out-File C:\ TempComputerLastLogonDa
你将要使用属性'lastlogontimestamp'而不是'lastlogon'。
LastLogonTimeStamp是在所有DC中复制的值,但不是确切的值。 它是可configuration的,但是(最后我知道)如果复制date超过14天,默认情况下是复制。
如果你正在寻找陈旧的机器账户(比如60天以上),那么你需要在这个账户上放置14天。
根据您现有的PS,您希望有助于确定AD中的旧电脑。
你可以在这里运行PS:
# Gets time stamps for all computers in the domain that have NOT logged in since after specified date # Mod by Tilo 2013-08-27 import-module activedirectory $domain = "domain.mydom.com" $DaysInactive = 90 $time = (Get-Date).Adddays(-($DaysInactive)) # Get all AD computers with lastLogonTimestamp less than our time Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | # Output hostname and lastLogonTimestamp into CSV select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv OLD_Computer.csv -notypeinformation
或者我个人从JoeWare长久的喜爱: