PowerShell – Return Machines Based Upon Logon Count

email me

Run on an AD network to return machines that have logged in X amount of times.

# MrNetTek
# eddiejackson.net/blog
# 6/1/2020
# free for public use
# free to claim as your own

Clear-Host

$Count = '2000'

$Filter = "(&(objectCategory=Computer)(logonCount>=$Count))"

$Domain = New-Object System.DirectoryServices.DirectoryEntry

$Search = New-Object System.DirectoryServices.DirectorySearcher
$Search.SearchRoot = $Domain
$Search.PageSize = 1000
$Search.Filter = $Filter

$colProplist = "name"

foreach ($i in $colPropList){$Search.PropertiesToLoad.Add($i)}

$colResults = $Search.FindAll()

foreach ($Result in $colResults)
    {$Item = $Result.Properties; $Item.name}

Write-Host "`nDone!"