Skip to content

Commit a192398

Browse files
Get-DbaNetworkEncryption - Wire up call to Get-SqlServerTlsCertificate
(do Get-DbaNetworkEncryption) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent bc835de commit a192398

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

dbatools.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
'Get-DbaMsdtc',
334334
'Get-DbaNetworkActivity',
335335
'Get-DbaNetworkCertificate',
336+
'Get-DbaNetworkEncryption',
336337
'Get-DbaNetworkConfiguration',
337338
'Get-DbaOpenTransaction',
338339
'Get-DbaOperatingSystem',

dbatools.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ if ($PSVersionTable.PSVersion.Major -lt 5) {
10681068
'Test-DbaComputerCertificateExpiration',
10691069
'Test-DbaNetworkCertificate',
10701070
'Get-DbaNetworkCertificate',
1071+
'Get-DbaNetworkEncryption',
10711072
'Set-DbaNetworkCertificate',
10721073
'Remove-DbaDbLogShipping',
10731074
'Invoke-DbaDbLogShipping',

public/Get-DbaNetworkEncryption.ps1

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,48 @@ function Get-DbaNetworkEncryption {
9292

9393
process {
9494
foreach ($instance in $SqlInstance) {
95-
9695
try {
96+
$computerName = $instance.ComputerName
97+
$instanceName = $instance.InstanceName
98+
$tlsInstanceName = if ($instanceName -eq "MSSQLSERVER") { "" } else { $instanceName }
99+
100+
$resolvedPort = if ($instance.Port -gt 0) {
101+
$instance.Port
102+
} elseif ($instanceName -eq "MSSQLSERVER") {
103+
1433
104+
} else {
105+
$null
106+
}
107+
108+
$sqlInstanceName = if ($instanceName -and $instanceName -ne "MSSQLSERVER") {
109+
"$computerName\$instanceName"
110+
} else {
111+
$computerName
112+
}
113+
114+
$splatTls = @{
115+
ComputerName = $computerName
116+
InstanceName = $tlsInstanceName
117+
}
118+
119+
if ($instance.Port -gt 0) {
120+
$splatTls.ConnectionType = "TCP"
121+
$splatTls.Port = $instance.Port
122+
}
123+
124+
$cert = Get-SqlServerTlsCertificate @splatTls
125+
126+
if (-not $cert) {
127+
continue
128+
}
97129

130+
$dnsNames = $cert.DnsNameList
98131

99132
[PSCustomObject]@{
100133
ComputerName = $computerName
101134
InstanceName = $instanceName
102135
SqlInstance = $sqlInstanceName
103-
Port = $port
136+
Port = $resolvedPort
104137
Subject = $cert.Subject
105138
Issuer = $cert.Issuer
106139
Thumbprint = $cert.Thumbprint
@@ -115,4 +148,4 @@ function Get-DbaNetworkEncryption {
115148
}
116149
}
117150
}
118-
}
151+
}

0 commit comments

Comments
 (0)