Skip to content

Instantly share code, notes, and snippets.

@iyre
Created February 18, 2020 23:31
Show Gist options
  • Save iyre/91d1d0d623b3e4a4c889e3a17b08642b to your computer and use it in GitHub Desktop.
Save iyre/91d1d0d623b3e4a4c889e3a17b08642b to your computer and use it in GitHub Desktop.
Get a list of active domain computers
$DateOffset = 30
$StartDate = (Get-Date).adddays(-($DateOffset))
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com"
Get-ADComputer -Filter {
( LastLogonDate -gt $StartDate ) -and
( Name -ne "$env:COMPUTERNAME" )
} -SearchBase $SearchBase -Properties LastLogonDate |
Sort-Object -Property LastLogonDate |
Format-Table -Property Name, LastLogonDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment