Import-Module ActiveDirectory $layout = “” $domain = “domain_name.local” $DaysInactive = 60 $d = (Get-Date).Adddays(-($DaysInactive)) $stale = Get-ADComputer -Filter ‘LastLogonTimeStamp -lt $d’ -Properties LastLogonTimeStamp $liststale = $stale | Sort Name | ConvertTo-HTML -Head $layout Name, DistinguishedName -Body “<p>The Following Machines Have Not Contacted the Domain in the Past “$DaysInactive” Days:</p>” $countstale = $stale | group-object computer | ConvertTo-HTML -Head $layout Count -Body “<p>Total Stale Machine Count</p>” $header = “<h1> Stale Computer Report</h1>” $message = “<p> The following computers have been detected as not being logged on in the last 60 days. Please clean up these computers from Active Directory. </p>”

$messageParameters = @{
Subject = “Stale Computer Report from $env:ComputerName.$env:USERDNSDOMAIN - $((Get-Date).ToShortDateString())”
Body = $header, $message, $countstale, $liststale | Out-String
From = “helpdesk@domain_name.qld.edu.au”
To = “kanderson@domain_name.qld.edu.au”,”helpdesk@domain_name.qld.edu.au” SmtpServer = “mail_server.domain_name.local”
}
Send-MailMessage @messageParameters -BodyAsHtml