Get active Computers in Forest
$ForestInfo=Get-ADForest
$Domains =$forestInfo.domains
$FileName =$ForestInfo.RootDomain+”-Windows_Servers_60-9_Days_Active-“+”$(get-date -Format MM-dd-yyyy)”+”.csv”
$FilePath = “c:\temp”
$Daysactive = 60
$lastactive=(get-date).AddDays(-($Daysactive))
foreach($domain in $domains){
Write-Output “Working on $domain”
Get-ADComputer -Filter {OperatingSystem -like “*server*” -and lastlogondate -gt $lastactive -and enabled -eq $true } -Property Name,DNSHostName,OperatingSystem,OperatingSystemServicePack,IPv4Address,LastLogonDate,Modified,Description,DistinguishedName,Created -Server $domain| select Name,DNSHostName,OperatingSystem,OperatingSystemServicePack,IPv4Address,LastLogonDate,Modified,Description,DistinguishedName,Created | Export-Csv -NoTypeInformation $FilePath\$FileName -append
}