Skip to content

Commit 5202a10

Browse files
authored
SqlProtocol/SqlProtocolTcpIp: Refactor to use public commands (#2368)
1 parent 443a52f commit 5202a10

File tree

10 files changed

+72
-286
lines changed

10 files changed

+72
-286
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
clarity. The old names `*-SqlDscBIReportServer` and `*-SqlDscPBIReportServer`
3838
are available as aliases for backward compatibility
3939
([issue #2071](https://github.com/dsccommunity/SqlServerDsc/issues/2071)).
40+
- `SqlProtocol`
41+
- Refactored to use the public command `Get-SqlDscServerProtocolName` instead
42+
of the deprecated private function `Get-ProtocolNameProperties`
43+
([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
44+
- Refactored to use the public command `Get-SqlDscServerProtocol` instead
45+
of the deprecated private function `Get-ServerProtocolObject`
46+
([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
47+
- `SqlProtocolTcpIp`
48+
- Refactored to use the public command `Get-SqlDscServerProtocol` instead
49+
of the deprecated private function `Get-ServerProtocolObject`
50+
([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
4051
- `SqlPermission`
4152
- Refactored to use the new object-based server permission commands
4253
(`Grant-SqlDscServerPermission`, `Deny-SqlDscServerPermission`,
@@ -96,6 +107,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
96107
`System.Management.Automation.SwitchParameter` to follow PowerShell best practices.
97108
([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
98109

110+
### Removed
111+
112+
- Removed deprecated private function `Get-ProtocolNameProperties` from the
113+
SqlServerDsc.Common module. Use the public command `Get-SqlDscServerProtocolName`
114+
instead ([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
115+
- Removed deprecated private function `Get-ServerProtocolObject` from the
116+
SqlServerDsc.Common module. Use the public command `Get-SqlDscServerProtocol`
117+
instead ([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
118+
99119
## [17.3.0] - 2025-12-01
100120

101121
### Removed

source/DSCResources/DSC_SqlProtocol/DSC_SqlProtocol.psm1

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function Get-TargetResource
8080
HasMultiIPAddresses = $false
8181
}
8282

83-
$protocolNameProperties = Get-ProtocolNameProperties -ProtocolName $ProtocolName
83+
$protocolNameProperties = Get-SqlDscServerProtocolName -ProtocolName $ProtocolName
8484

8585
# Getting the server protocol properties by using the computer name.
8686
$computerName = Get-ComputerName
@@ -95,13 +95,13 @@ function Get-TargetResource
9595
Must connect to the local machine name because $ServerName can point
9696
to a cluster instance or availability group listener.
9797
#>
98-
$getServerProtocolObjectParameters = @{
98+
$getSqlDscServerProtocolParameters = @{
9999
ServerName = $computerName
100-
Instance = $InstanceName
100+
InstanceName = $InstanceName
101101
ProtocolName = $ProtocolName
102102
}
103103

104-
$serverProtocolProperties = Get-ServerProtocolObject @getServerProtocolObjectParameters
104+
$serverProtocolProperties = Get-SqlDscServerProtocol @getSqlDscServerProtocolParameters
105105

106106
if ($serverProtocolProperties)
107107
{
@@ -229,12 +229,10 @@ function Set-TargetResource
229229
$RestartTimeout = 120
230230
)
231231

232-
$protocolNameProperties = Get-ProtocolNameProperties -ProtocolName $ProtocolName
232+
$protocolNameProperties = Get-SqlDscServerProtocolName -ProtocolName $ProtocolName
233233

234234
<#
235-
Compare the current state against the desired state. Calling this will
236-
also import the necessary module to later call Get-ServerProtocolObject
237-
which uses the SMO class ManagedComputer.
235+
Compare the current state against the desired state.
238236
#>
239237
$propertyState = Compare-TargetResourceState @PSBoundParameters
240238

@@ -254,13 +252,13 @@ function Set-TargetResource
254252
Must connect to the local machine name because $ServerName can point
255253
to a cluster instance or availability group listener.
256254
#>
257-
$getServerProtocolObjectParameters = @{
255+
$getSqlDscServerProtocolParameters = @{
258256
ServerName = $computerName
259-
Instance = $InstanceName
257+
InstanceName = $InstanceName
260258
ProtocolName = $ProtocolName
261259
}
262260

263-
$serverProtocolProperties = Get-ServerProtocolObject @getServerProtocolObjectParameters
261+
$serverProtocolProperties = Get-SqlDscServerProtocol @getSqlDscServerProtocolParameters
264262

265263
if ($serverProtocolProperties)
266264
{
@@ -459,7 +457,7 @@ function Test-TargetResource
459457
$RestartTimeout = 120
460458
)
461459

462-
$protocolNameProperties = Get-ProtocolNameProperties -ProtocolName $ProtocolName
460+
$protocolNameProperties = Get-SqlDscServerProtocolName -ProtocolName $ProtocolName
463461

464462
Write-Verbose -Message (
465463
$script:localizedData.TestDesiredState -f $protocolNameProperties.DisplayName, $InstanceName, $ServerName

source/DSCResources/DSC_SqlProtocolTcpIp/DSC_SqlProtocolTcpIp.psm1

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ function Get-TargetResource
103103
Must connect to the local machine name because $ServerName can point
104104
to a cluster instance or availability group listener.
105105
#>
106-
$getServerProtocolObjectParameters = @{
106+
$getSqlDscServerProtocolParameters = @{
107107
ServerName = $computerName
108-
Instance = $InstanceName
108+
InstanceName = $InstanceName
109109
ProtocolName = 'TcpIp'
110110
}
111111

112-
$serverProtocolProperties = Get-ServerProtocolObject @getServerProtocolObjectParameters
112+
$serverProtocolProperties = Get-SqlDscServerProtocol @getSqlDscServerProtocolParameters
113113

114114
if ($serverProtocolProperties)
115115
{
@@ -274,9 +274,7 @@ function Set-TargetResource
274274
$IpAddressGroup = Convert-IpAdressGroupCasing -IpAddressGroup $IpAddressGroup
275275

276276
<#
277-
Compare the current state against the desired state. Calling this will
278-
also import the necessary module to later call Get-ServerProtocolObject
279-
which uses the SMO class ManagedComputer.
277+
Compare the current state against the desired state.
280278
#>
281279
$propertyState = Compare-TargetResourceState @PSBoundParameters
282280

@@ -296,13 +294,13 @@ function Set-TargetResource
296294
Must connect to the local machine name because $ServerName can point
297295
to a cluster instance or availability group listener.
298296
#>
299-
$getServerProtocolObjectParameters = @{
297+
$getSqlDscServerProtocolParameters = @{
300298
ServerName = $computerName
301-
Instance = $InstanceName
299+
InstanceName = $InstanceName
302300
ProtocolName = 'TcpIp'
303301
}
304302

305-
$serverProtocolProperties = Get-ServerProtocolObject @getServerProtocolObjectParameters
303+
$serverProtocolProperties = Get-SqlDscServerProtocol @getSqlDscServerProtocolParameters
306304

307305
if ($serverProtocolProperties)
308306
{

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
'Find-ExceptionByNumber'
4646
'Compare-ResourcePropertyState'
4747
'Test-DscPropertyState'
48-
'Get-ProtocolNameProperties'
49-
'Get-ServerProtocolObject'
5048
'Import-Assembly'
5149
'ConvertTo-ServerInstanceName'
5250
'Get-FilePathMajorVersion'

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,126 +1943,6 @@ function Find-ExceptionByNumber
19431943
return $errorFound
19441944
}
19451945

1946-
<#
1947-
.SYNOPSIS
1948-
Get static name properties of he specified protocol.
1949-
1950-
.PARAMETER ProtocolName
1951-
Specifies the name of network protocol to return name properties for.
1952-
Possible values are 'TcpIp', 'NamedPipes', or 'ShareMemory'.
1953-
1954-
.NOTES
1955-
The static values returned matches the values returned by the class
1956-
ServerProtocol. The property DisplayName could potentially be localized
1957-
while the property Name must be exactly like it is returned by the
1958-
class ServerProtocol, with the correct casing.
1959-
1960-
The Get-ProtocolNameProperties function is deprecated and should be removed
1961-
in the future when existing code has moved to new public commands.
1962-
#>
1963-
function Get-ProtocolNameProperties
1964-
{
1965-
[CmdletBinding()]
1966-
[OutputType([System.Collections.Hashtable])]
1967-
param
1968-
(
1969-
[Parameter(Mandatory = $true)]
1970-
[ValidateSet('TcpIp', 'NamedPipes', 'SharedMemory')]
1971-
[System.String]
1972-
$ProtocolName
1973-
)
1974-
1975-
$protocolNameProperties = @{ }
1976-
1977-
switch ($ProtocolName)
1978-
{
1979-
'TcpIp'
1980-
{
1981-
$protocolNameProperties.DisplayName = 'TCP/IP'
1982-
$protocolNameProperties.Name = 'Tcp'
1983-
}
1984-
1985-
'NamedPipes'
1986-
{
1987-
$protocolNameProperties.DisplayName = 'Named Pipes'
1988-
$protocolNameProperties.Name = 'Np'
1989-
}
1990-
1991-
'SharedMemory'
1992-
{
1993-
$protocolNameProperties.DisplayName = 'Shared Memory'
1994-
$protocolNameProperties.Name = 'Sm'
1995-
}
1996-
}
1997-
1998-
return $protocolNameProperties
1999-
}
2000-
2001-
<#
2002-
.SYNOPSIS
2003-
Returns the ServerProtocol object for the specified SQL Server instance
2004-
and protocol name.
2005-
2006-
.PARAMETER InstanceName
2007-
Specifies the name of the SQL Server instance to connect to.
2008-
2009-
.PARAMETER ProtocolName
2010-
Specifies the name of network protocol to be configured. Possible values
2011-
are 'TcpIp', 'NamedPipes', or 'ShareMemory'.
2012-
2013-
.PARAMETER ServerName
2014-
Specifies the host name of the SQL Server to connect to.
2015-
2016-
.NOTES
2017-
The class Microsoft.SqlServer.Management.Smo.Wmi.ServerProtocol is
2018-
returned by this function.
2019-
#>
2020-
function Get-ServerProtocolObject
2021-
{
2022-
[CmdletBinding()]
2023-
param
2024-
(
2025-
[Parameter(Mandatory = $true)]
2026-
[System.String]
2027-
$InstanceName,
2028-
2029-
[Parameter(Mandatory = $true)]
2030-
[ValidateSet('TcpIp', 'NamedPipes', 'SharedMemory')]
2031-
[System.String]
2032-
$ProtocolName,
2033-
2034-
[Parameter(Mandatory = $true)]
2035-
[ValidateNotNullOrEmpty()]
2036-
[System.String]
2037-
$ServerName
2038-
)
2039-
2040-
$serverProtocolProperties = $null
2041-
2042-
$newObjectParameters = @{
2043-
TypeName = 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'
2044-
ArgumentList = @($ServerName)
2045-
}
2046-
2047-
$managedComputerObject = New-Object @newObjectParameters
2048-
2049-
$serverInstance = $managedComputerObject.ServerInstances[$InstanceName]
2050-
2051-
if ($serverInstance)
2052-
{
2053-
$protocolNameProperties = Get-ProtocolNameProperties -ProtocolName $ProtocolName
2054-
2055-
$serverProtocolProperties = $serverInstance.ServerProtocols[$protocolNameProperties.Name]
2056-
}
2057-
else
2058-
{
2059-
$errorMessage = $script:localizedData.FailedToObtainServerInstance -f $InstanceName, $ServerName
2060-
New-InvalidOperationException -Message $errorMessage
2061-
}
2062-
2063-
return $serverProtocolProperties
2064-
}
2065-
20661946
<#
20671947
.SYNOPSIS
20681948
Converts the combination of server name and instance name to

source/Modules/SqlServerDsc.Common/en-US/SqlServerDsc.Common.strings.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ ConvertFrom-StringData @'
4343
NotOwnerOfClusterResource = The node '{0}' is not the owner of the cluster resource '{1}'. The owner is '{2}' so no restart is needed. (SQLCOMMON0067)
4444
LoadedAssembly = Loaded the assembly '{0}'. (SQLCOMMON0068)
4545
FailedToLoadAssembly = Failed to load the assembly '{0}'. (SQLCOMMON0069)
46-
FailedToObtainServerInstance = Failed to obtain a SQL Server instance with name '{0}' on server '{1}'. Ensure the SQL Server instance exists on the server and that the 'SQLServer' module references a version of the 'Microsoft.SqlServer.Management.Smo.Wmi' library that supports the version of the SQL Server instance. (SQLCOMMON0070)
4746
DatabaseEngineInstanceNotOnline = The SQL instance '{0}' was expected to have the status 'Online', but had status '{1}'. (SQLCOMMON0071)
4847
WaitForDatabaseEngineInstanceStatus = The SQL instance status is '{0}' expected '{1}', waiting {2} seconds. (SQLCOMMON0072)
4948
'@

source/Modules/SqlServerDsc.Common/sv-SE/SqlServerDsc.Common.strings.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ ConvertFrom-StringData @'
4949
NotOwnerOfClusterResource = The node '{0}' is not the owner of the cluster resource '{1}'. The owner is '{2}' so no restart is needed. (SQLCOMMON0067)
5050
LoadedAssembly = Loaded the assembly '{0}'. (SQLCOMMON0068)
5151
FailedToLoadAssembly = Failed to load the assembly '{0}'. (SQLCOMMON0069)
52-
FailedToObtainServerInstance = Failed to obtain a SQL Server instance with name '{0}' on server '{1}'. Ensure the SQL Server instance exists on the server and that the 'SQLServer' module references a version of the 'Microsoft.SqlServer.Management.Smo.Wmi' library that supports the version of the SQL Server instance. (SQLCOMMON0070)
5352
DatabaseEngineInstanceNotOnline = The SQL instance '{0}' was expected to have the status 'Online', but had status '{1}'. (SQLCOMMON0071)
5453
WaitForDatabaseEngineInstanceStatus = The SQL instance status is '{0}' expected '{1}', waiting {2} seconds. (SQLCOMMON0072)
5554
'@

0 commit comments

Comments
 (0)