Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created October 18, 2016 03:40
Show Gist options
  • Save chrisbrownie/9b86179c5b7e90974834666b34d3e3e1 to your computer and use it in GitHub Desktop.
Save chrisbrownie/9b86179c5b7e90974834666b34d3e3e1 to your computer and use it in GitHub Desktop.
Gets computers that have a certificate matching a thumbprint
$thumbprintsToSearchFor = @(
"aabbccddeeffgg"
)
$OUs = @(
"OU=Servers,DC=contoso,DC=com",
"OU=OtherServers,DC=contoso,DC=com"
)
$logonHistoryDays = 90
foreach ($OU in $OUs) {
$servers = Get-ADComputer -SearchBase $OU -Properties LastLogonDate -Filter *
$servers = $servers | Where {$_.LastLogonDate -gt ((Get-Date).AddDays(-$logonHistoryDays))}
foreach ($s in $servers) {
try {
$CertStore = New-Object System.Security.Cryptography.X509Certificates.X509Store "\\$($s.name)\My","LocalMachine"
$CertStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
foreach($Cert in $CertStore.Certificates){
if ($thumbprintsToSearchFor -contains $cert.thumbprint) {
"$($s.name) has $($cert.Thumbprint)"
}
}
$CertStore.Close()
} catch {
"Failed: $($s.name)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment