Skip to content

Commit

Permalink
Updated the way the subject name is parsed against the DNS resolved n…
Browse files Browse the repository at this point in the history
…ame of the machine 🐎
  • Loading branch information
blakedrumm authored May 5, 2024
1 parent 37f9dda commit 969d4ab
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Powershell/Test-SCOMCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
Check all certificates on the local machine:
PS C:\> .\Test-SCOMCertificates.ps1 -All
.NOTES
Update 05/2024 (Blake Drumm, https://blakedrumm.com/)
Updated the way the subject name is parsed against the DNS resolved name of the machine.
Update 03/2024 (Blake Drumm, https://blakedrumm.com/)
Changed the name from Start-SCOMCertificateChecker to Test-SCOMCertificate.
Update 05/2023 (Blake Drumm, https://blakedrumm.com/)
Expand Down Expand Up @@ -286,15 +288,14 @@ $($ChainCertsOutput)
$out += "`n" + "`n" + $text4
$pass = $true
# Check subjectname
$fqdn = $env:ComputerName
$fqdn += "." + [DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name
$fqdn = (Resolve-DnsName $env:COMPUTERNAME -Type A | Select-Object -ExpandProperty Name -Unique) -join " "
trap [DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException]
{
# Not part of a domain
continue;
}
$subjectProblem = $false
$fqdnRegexPattern = "CN=" + $fqdn.Replace(".", "\.") + '(,.*)?$'
$fqdnRegexPattern = "CN=" + ($fqdn.Replace(".", "\.")).Replace(" ", "|CN=")
try { $CheckForDuplicateSubjectCNs = ((($cert).Subject).Split(",") | %{ $_.Trim() } | Where { $_ -match "CN=" }).Trim("CN=") | % { $_.Split(".") | Select-Object -First 1 } | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name }
catch { $CheckForDuplicateSubjectCNs = $null }

Expand Down Expand Up @@ -755,6 +756,7 @@ Certificate Checker
continue
}
#endregion Function

#region DefaultActions
if ($Servers -or $OutputFile -or $All -or $SerialNumber)
{
Expand Down

0 comments on commit 969d4ab

Please sign in to comment.