Skip to content

Instantly share code, notes, and snippets.

@cactaceae21
Last active May 13, 2021 13:37
Show Gist options
  • Save cactaceae21/5c77523152aff8e73e558abfc8c3c4a2 to your computer and use it in GitHub Desktop.
Save cactaceae21/5c77523152aff8e73e558abfc8c3c4a2 to your computer and use it in GitHub Desktop.
Active Directory #AD #Windows
## Multiple filters
$searchOU = "OU=Workstations,DC=XX,DC=XXXX, DC=org"
$date = (get-date).AddDays(-60)
$Workstations = Get-ADComputer -Filter {LastLogonTimeStamp -lt $date -and enabled -eq $true} -SearchBase $SearchOU -Properties Enabled, LastLogonTimeStamp, LastLogonDate
$Workstations | select name, lastlogondate
## Find MS SQL servers by SPN
Get-ADComputer -Filter { serviceprincipalname -like 'MSSQLSvc/*' }
Get-ADComputer -LDAPFilter "(servicePrincipalName=MSSQLSvc/*)"
Get-ADObject -Filter { (serviceprincipalname -like 'MSSQLSvc/*') -and (objectcategory -eq 'computer') }
Get-ADObject -LDAPFilter "(&(objectcategory=computer)(servicePrincipalName=MSSQLSvc/*))"
## Find MS SQL CLUSTER virtual servers
Get-ADObject -Filter { (serviceprincipalname -like 'MSClusterVirtualServer/*') -and (objectcategory -eq 'computer') }
Get-ADObject -LDAPFilter "(&(objectcategory=computer)(servicePrincipalName=MSClusterVirtualServer/*))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment