Book now with code EOY2025
LeifAlire wrote: » dsquery computer -inactive 4 < this command shows you computers that haven't connected in last 4 weeks. Change the number to match what you need.
$ou = [ADSI]"LDAP://OU=STAFFOU,OU=Workstations,DC=herp,DC=gov" $Date = [DateTime]::Now.AddDays(-30) foreach ($strComputer in $ou.psbase.Children) { $Computer = $strComputer.name if (Test-Connection -ComputerName $Computer -Count 1 -Quiet -EA 0) { $Date.tostring("MM-dd-yyyy"), $Computer $eventList = @() Get-EventLog "Security" -computername $Computer -After $Date ` | Where -FilterScript {$_.EventID -eq 4624 -and $_.ReplacementStrings[4].Length -gt 10 -and $_.ReplacementStrings[5] -notlike "*$"} ` | select -first 3 ` | foreach-Object { $row = "" | Select UserName, LoginTime $row.UserName = $_.ReplacementStrings[5] $row.LoginTime = $_.TimeGenerated $eventList += $row } $eventList write-host "" } else { Write-Host "Couldn't ping $Computer so no logon data available." -BackgroundColor RED -ForegroundColor White write-host "" } }
Use code EOY2025 to receive $250 off your 2025 certification boot camp!