Skip to content

Commit 969d4ab

Browse files
authored
Updated the way the subject name is parsed against the DNS resolved name of the machine 🐎
1 parent 37f9dda commit 969d4ab

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Powershell/Test-SCOMCertificate.ps1

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
Check all certificates on the local machine:
2929
PS C:\> .\Test-SCOMCertificates.ps1 -All
3030
.NOTES
31+
Update 05/2024 (Blake Drumm, https://blakedrumm.com/)
32+
Updated the way the subject name is parsed against the DNS resolved name of the machine.
3133
Update 03/2024 (Blake Drumm, https://blakedrumm.com/)
3234
Changed the name from Start-SCOMCertificateChecker to Test-SCOMCertificate.
3335
Update 05/2023 (Blake Drumm, https://blakedrumm.com/)
@@ -286,15 +288,14 @@ $($ChainCertsOutput)
286288
$out += "`n" + "`n" + $text4
287289
$pass = $true
288290
# Check subjectname
289-
$fqdn = $env:ComputerName
290-
$fqdn += "." + [DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name
291+
$fqdn = (Resolve-DnsName $env:COMPUTERNAME -Type A | Select-Object -ExpandProperty Name -Unique) -join " "
291292
trap [DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException]
292293
{
293294
# Not part of a domain
294295
continue;
295296
}
296297
$subjectProblem = $false
297-
$fqdnRegexPattern = "CN=" + $fqdn.Replace(".", "\.") + '(,.*)?$'
298+
$fqdnRegexPattern = "CN=" + ($fqdn.Replace(".", "\.")).Replace(" ", "|CN=")
298299
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 }
299300
catch { $CheckForDuplicateSubjectCNs = $null }
300301

@@ -755,6 +756,7 @@ Certificate Checker
755756
continue
756757
}
757758
#endregion Function
759+
758760
#region DefaultActions
759761
if ($Servers -or $OutputFile -or $All -or $SerialNumber)
760762
{

0 commit comments

Comments
 (0)