Created
October 18, 2016 03:40
-
-
Save chrisbrownie/9b86179c5b7e90974834666b34d3e3e1 to your computer and use it in GitHub Desktop.
Gets computers that have a certificate matching a thumbprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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