Skip to content

Commit 984dd2d

Browse files
Add ability to gather verbosely.
1 parent 5d44a80 commit 984dd2d

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

Powershell/Get-TLSRegistryKeys.ps1

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
PS C:\> .\Get-TLSRegistryKeys.ps1
1313
1414
.NOTES
15+
16+
Original Author: Mike Kallhoff
1517
Author: Blake Drumm (blakedrumm@microsoft.com)
1618
1719
Hosted here: https://github.com/blakedrumm/SCOM-Scripts-and-SQL/blob/master/Powershell/Get-TLSRegistryKeys.ps1
@@ -38,6 +40,9 @@ Function Get-TLSRegistryKeys
3840

3941
function Inner-TLSRegKeysFunction
4042
{
43+
[CmdletBinding()]
44+
param ()
45+
4146
$finalData = @()
4247
$LHost = $env:computername
4348
$ProtocolList = "TLS 1.0", "TLS 1.1", "TLS 1.2"
@@ -51,6 +56,7 @@ Function Get-TLSRegistryKeys
5156

5257
foreach ($key in $ProtocolSubKeyList)
5358
{
59+
Write-Host "-" -NoNewline -ForegroundColor Green
5460
#Write-Host "Checking for $protocol\$key"
5561
$currentRegPath = $registryPath + $Protocol + "\" + $key
5662
$IsDisabledByDefault = @()
@@ -136,33 +142,27 @@ Function Get-TLSRegistryKeys
136142
## ODBC : https://www.microsoft.com/en-us/download/details.aspx?id=50420
137143
## OLEDB : https://docs.microsoft.com/en-us/sql/connect/oledb/download-oledb-driver-for-sql-server?view=sql-server-ver15
138144
[string[]]$data = (Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*sql*" }).name
139-
$odbc = $data | where { $_ -like "Microsoft ODBC Driver *" } # Need to validate version
140-
if ($odbc -match "11|13")
145+
$odbcOutput = $data | where { $_ -like "Microsoft ODBC Driver *" } # Need to validate version
146+
$odbc = @()
147+
foreach ($driver in $odbcOutput)
141148
{
142-
$odbc = $null
143-
$odbc = @()
144-
foreach ($driver in $odbc)
149+
Write-Host '-' -NoNewline -ForegroundColor Green
150+
if ($driver -match "11|13")
145151
{
146152
Write-Verbose "FOUND $driver"
147153
$odbc += "$driver (Good)"
148154
}
149-
150-
}
151-
elseif ($odbc)
152-
{
153-
$odbc = $null
154-
$odbc = @()
155-
foreach ($driver in $odbc)
155+
elseif ($driver)
156156
{
157157
Write-Verbose "FOUND $driver"
158158
$odbc += "$driver"
159159
}
160-
161-
}
162-
else
163-
{
164-
$odbc = "Not Found."
160+
else
161+
{
162+
$odbc = "Not Found."
163+
}
165164
}
165+
$odbc = $odbc.Split("`n") | Out-String -Width 2048
166166
$oledb = $data | where { $_ -eq 'Microsoft OLE DB Driver for SQL Server' }
167167
if ($oledb)
168168
{
@@ -175,7 +175,7 @@ Function Get-TLSRegistryKeys
175175
}
176176
foreach ($Protocol in $ProtocolList)
177177
{
178-
178+
Write-Host '-' -NoNewline -ForegroundColor Green
179179
foreach ($key in $ProtocolSubKeyList)
180180
{
181181
#Write-Host "Checking for $protocol\$key"
@@ -225,7 +225,7 @@ Function Get-TLSRegistryKeys
225225
[version]$SQLClient11Version = [version]$SQLClient11VersionString
226226
}
227227
[version]$MinSQLClient11Version = [version]"11.4.7001.0"
228-
228+
Write-Host '-' -NoNewline -ForegroundColor Green
229229
IF ($SQLClient11Version -ge $MinSQLClient11Version)
230230
{
231231
Write-Verbose "SQL Client - is installed and version: ($SQLClient11VersionString) and greater or equal to the minimum version required: (11.4.7001.0)"
@@ -270,6 +270,7 @@ Function Get-TLSRegistryKeys
270270
"528049" { ".NET Framework 4.8" }
271271
default { "Unknown .NET version: $ReleaseRegValue" }
272272
}
273+
Write-Host '-' -NoNewline -ForegroundColor Green
273274
# Check if version is 4.6 or higher
274275
IF ($ReleaseRegValue -ge 393295)
275276
{
@@ -298,6 +299,7 @@ Function Get-TLSRegistryKeys
298299
}
299300
try
300301
{
302+
Write-Host '-' -NoNewline -ForegroundColor Green
301303
$odbcODBCDataSources = Get-ItemProperty 'Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources' -ErrorAction Stop | Select-Object OpsMgrAC -ExpandProperty OpsMgrAC
302304
}
303305
catch { $odbcODBCDataSources = 'Not Found.' }
@@ -330,27 +332,42 @@ Function Get-TLSRegistryKeys
330332
if ($server -notcontains $env:COMPUTERNAME)
331333
{
332334
$InnerTLSRegKeysFunctionScript = "function Inner-TLSRegKeysFunction { ${function:Inner-TLSRegKeysFunction} }"
333-
$scriptOut += (Invoke-Command -ComputerName $server -ArgumentList $InnerTLSRegKeysFunctionScript -ScriptBlock {
334-
Param ($script)
335+
$scriptOut += (Invoke-Command -ComputerName $server -ArgumentList $InnerTLSRegKeysFunctionScript, $VerbosePreference -ScriptBlock {
336+
Param ($script,
337+
$VerbosePreference)
335338
. ([ScriptBlock]::Create($script))
336339
Write-Host "-" -NoNewLine -ForegroundColor Green
337-
return Inner-TLSRegKeysFunction
340+
if ($VerbosePreference -eq 'Continue')
341+
{
342+
return Inner-TLSRegKeysFunction -Verbose
343+
}
344+
else
345+
{
346+
return Inner-TLSRegKeysFunction
347+
}
338348
} -HideComputerName | Out-String) -replace "RunspaceId.*", ""
339349
Write-Host "> Completed!`n" -NoNewline -ForegroundColor Green
340350

341351
}
342352
else
343353
{
344354
Write-Host "-" -NoNewLine -ForegroundColor Green
345-
$scriptOut += Inner-TLSRegKeysFunction
355+
if ($VerbosePreference -eq 'Continue')
356+
{
357+
$scriptOut += Inner-TLSRegKeysFunction -Verbose
358+
}
359+
else
360+
{
361+
$scriptOut += Inner-TLSRegKeysFunction
362+
}
346363
Write-Host "> Completed!`n" -NoNewline -ForegroundColor Green
347364
}
348365
}
349366
$scriptOut | Out-String -Width 4096
350367
}
351368
if ($Servers)
352369
{
353-
Get-TLSRegistryKeys -Servers $Servers
370+
Get-TLSRegistryKeys -Servers $Servers -Verbose:$VerbosePreference -Debug:$DebugPreference
354371
}
355372
else
356373
{

0 commit comments

Comments
 (0)