Check Active Directory for Stale Computers

Several times I have need to generate a list of computers that are identified as stale, but as an extra measure I want to try pinging them. This s

Managing VMware Snapshots with Powershell
Removing an installed Windows Update
Changing PWDLASTSET in Active Directory

Several times I have need to generate a list of computers that are identified as stale, but as an extra measure I want to try pinging them. This snippet will do just that.

Green – Not Stale and Online
Yellow – Stale but Online (these could be troublesome computers)
Red – Stale and Offline (these most likely can be removed from Active Directory)

# This uses the PasswordLastSet property to determine if the account is stale, it is set to 90 days however you can change it to what you need. Ping is set to 1 with smaller buffer.

Import-Module active*
$rtn = $null
Get-ADComputer -Filter * -properties * |
ForEach-Object {
$rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
IF($rtn -match ‘True’) {write-host -ForegroundColor green $_.dnshostname}
ELSE {
$date = [DateTime]::Today.AddDays(-90)
If ($_.PasswordLastSet -le $date)  {
Write-host -ForegroundColor red $_.dnshostname ” ” $_.PasswordLastSet ” Stale/Offline” }
else  {
Write-host -ForegroundColor yellow $_.dnshostname ” ” $_.PasswordLastSet ” Offline”  }}}

COMMENTS

WORDPRESS: 0