# Gets time stamps for all computers in the domain that have NOT logged in since after specified date
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 InactiveDomainComputer.csv -notypeinformation
Ce script interroge l’active directory afin d’établir une liste d’ordinateurs ne s’étant pas connectés depuis 90 jours, puis sauvegarde cette liste au format CSV.