-
Notifications
You must be signed in to change notification settings - Fork 227
Add new public commands #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
johlju
merged 31 commits into
main
from
copilot/fix-573e03dc-fd5a-4b2c-bee5-e2c7a757794d
Sep 13, 2025
Merged
Add new public commands #2108
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3f28687
Initial plan
Copilot c6c92c4
Add Get-SqlDscServerProtocol public command with CIM and SMO support
Copilot 6cff221
Merge branch 'main' into copilot/fix-573e03dc-fd5a-4b2c-bee5-e2c7a757…
johlju 2cfee78
Remove CIM functionality and refactor Get-SqlDscServerProtocol to use…
Copilot f49f1a4
Add Get-SqlDscServerProtocolName command and enhance Get-SqlDscServer…
Copilot 0b368eb
Address PR feedback: Add new commands, fix parameter sets, error hand…
Copilot 42f21fc
Address PR feedback: Fix variable casing, remove unused code, update …
Copilot 63ca2cc
Fix formatting and add suppression message for Get-SqlDscServerProtoc…
johlju 8727349
Merge branch 'main' into copilot/fix-573e03dc-fd5a-4b2c-bee5-e2c7a757…
johlju bc0c1ba
Fix error message in Get-SqlDscServerProtocol function to use correct…
johlju 31124a0
Refactor tests to unify module name variable and enhance localized st…
johlju 9dd30e3
Add integration tests for Get-SqlDscManagedComputerInstance, Get-SqlD…
johlju 4c7b7c5
Remove mandatory parameter from Get-SqlDscServerProtocol function and…
johlju f0645f8
Re-add and enhance documentation for Get-SqlDscServerProtocol, Get-Sq…
johlju 693ceb6
Enhance parameter type for ManagedComputerObject in Get-SqlDscManaged…
johlju 2128c50
Remove redundant test for non-existent protocol in Get-SqlDscServerPr…
johlju f8f6c02
Refactor Get-SqlDscManagedComputerInstance tests to use ServerInstanc…
johlju ef18634
Deprecate Get-ProtocolNameProperties function and add removal notice
johlju df1b732
Remove deprecated notes and handle empty server protocol case in Get-…
johlju f117c72
Remove redundant comment for Get-SqlDscServerProtocol section in SqlS…
johlju 71d5c86
Add validation for expected result count in Get-SqlDscManagedComputer…
johlju 622cfa2
Fix type assertion for Get-SqlDscManagedComputerInstance results to u…
johlju 99401dc
Update type assertion in Get-SqlDscServerProtocol tests to use Server…
johlju 2d78fe4
Fix type assertion for Get-SqlDscServerProtocolName test to use corre…
johlju 922046f
Update Get-SqlDscServerProtocol tests to suppress result assignment a…
johlju a32c295
Fix type assertion in Get-SqlDscServerProtocol tests to use ServerPro…
johlju 96b2128
Fix type assertion in Get-SqlDscServerProtocolName test to use correc…
johlju 8be8c6d
Implement IEnumerable interface in ServerProtocolCollection and make …
johlju 6d588c3
Enhance error handling in Get-SqlDscServerProtocol by adding ErrorAct…
johlju 06e8f53
Clarify guidelines for using $ErrorActionPreference by specifying to …
johlju edef06e
Fix missing newline at end of Get-SqlDscServerProtocolName.Tests.ps1
johlju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Returns managed computer server instance information. | ||
|
|
||
| .DESCRIPTION | ||
| Returns managed computer server instance information for a SQL Server instance | ||
| using SMO (SQL Server Management Objects). The command can retrieve a specific | ||
| instance or all instances on a managed computer. | ||
|
|
||
| .PARAMETER ServerName | ||
| Specifies the name of the server where the SQL Server instance is running. | ||
| Defaults to the local computer name. | ||
|
|
||
| .PARAMETER InstanceName | ||
| Specifies the name of the SQL Server instance to retrieve. | ||
| If not specified, all instances are returned. | ||
|
|
||
| .PARAMETER ManagedComputerObject | ||
| Specifies a managed computer object from which to retrieve server instances. | ||
| This parameter accepts pipeline input from Get-SqlDscManagedComputer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputerInstance -InstanceName 'MSSQLSERVER' | ||
|
|
||
| Returns the default SQL Server instance information from the local computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputerInstance -ServerName 'MyServer' -InstanceName 'MyInstance' | ||
|
|
||
| Returns the MyInstance SQL Server instance information from the MyServer computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputerInstance -ServerName 'MyServer' | ||
|
|
||
| Returns all SQL Server instances information from the MyServer computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputer -ServerName 'MyServer' | Get-SqlDscManagedComputerInstance -InstanceName 'MyInstance' | ||
|
|
||
| Uses pipeline input to retrieve a specific instance from a managed computer object. | ||
|
|
||
| .INPUTS | ||
| Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer | ||
|
|
||
| A managed computer object can be piped to this command. | ||
|
|
||
| .OUTPUTS | ||
| Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance | ||
|
|
||
| Returns server instance objects from SMO (SQL Server Management Objects). | ||
|
|
||
| .NOTES | ||
| This command uses SMO (SQL Server Management Objects) to retrieve server | ||
| instance information from the specified managed computer. | ||
| #> | ||
| function Get-SqlDscManagedComputerInstance | ||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')] | ||
| [CmdletBinding(DefaultParameterSetName = 'ByServerName')] | ||
| [OutputType([Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance])] | ||
| param | ||
| ( | ||
| [Parameter(ParameterSetName = 'ByServerName')] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $ServerName = (Get-ComputerName), | ||
|
|
||
| [Parameter(ParameterSetName = 'ByServerName')] | ||
| [Parameter(ParameterSetName = 'ByManagedComputerObject')] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $InstanceName, | ||
|
|
||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'ByManagedComputerObject')] | ||
| [Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer] | ||
| $ManagedComputerObject | ||
| ) | ||
|
|
||
| process | ||
| { | ||
| if ($PSCmdlet.ParameterSetName -eq 'ByServerName') | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ManagedComputerInstance_GetFromServer -f $ServerName | ||
| ) | ||
|
|
||
| $ManagedComputerObject = Get-SqlDscManagedComputer -ServerName $ServerName | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ManagedComputerInstance_GetFromObject | ||
| ) | ||
| } | ||
|
|
||
| if ($PSBoundParameters.ContainsKey('InstanceName')) | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ManagedComputerInstance_GetSpecificInstance -f $InstanceName | ||
| ) | ||
|
|
||
| $serverInstance = $ManagedComputerObject.ServerInstances[$InstanceName] | ||
|
|
||
| if (-not $serverInstance) | ||
| { | ||
| $errorMessage = $script:localizedData.ManagedComputerInstance_InstanceNotFound -f $InstanceName, $ManagedComputerObject.Name | ||
| $errorRecord = [System.Management.Automation.ErrorRecord]::new( | ||
| [System.InvalidOperationException]::new($errorMessage), | ||
| 'SqlServerInstanceNotFound', | ||
| [System.Management.Automation.ErrorCategory]::ObjectNotFound, | ||
| $InstanceName | ||
| ) | ||
| $PSCmdlet.ThrowTerminatingError($errorRecord) | ||
| } | ||
|
|
||
| return $serverInstance | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ManagedComputerInstance_GetAllInstances | ||
| ) | ||
|
|
||
| return $ManagedComputerObject.ServerInstances | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Returns server protocol information for a SQL Server instance. | ||
|
|
||
| .DESCRIPTION | ||
| Returns server protocol information for a SQL Server instance using | ||
| SMO (SQL Server Management Objects). The command supports getting | ||
| information for TcpIp, NamedPipes, and SharedMemory protocols. | ||
| If no protocol is specified, all protocols are returned. | ||
|
|
||
| .PARAMETER ServerName | ||
| Specifies the name of the server where the SQL Server instance is running. | ||
| Defaults to the local computer name. | ||
|
|
||
| .PARAMETER InstanceName | ||
| Specifies the name of the SQL Server instance for which to return protocol | ||
| information. | ||
|
|
||
| .PARAMETER ProtocolName | ||
| Specifies the name of the network protocol to return information for. | ||
| Valid values are 'TcpIp', 'NamedPipes', and 'SharedMemory'. | ||
| If not specified, all protocols are returned. | ||
|
|
||
| .PARAMETER ManagedComputerObject | ||
| Specifies a managed computer object from which to retrieve server protocol | ||
| information. This parameter accepts pipeline input from Get-SqlDscManagedComputer. | ||
|
|
||
| .PARAMETER ManagedComputerInstanceObject | ||
| Specifies a managed computer instance object from which to retrieve server | ||
| protocol information. This parameter accepts pipeline input from | ||
| Get-SqlDscManagedComputerInstance. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscServerProtocol -InstanceName 'MSSQLSERVER' -ProtocolName 'TcpIp' | ||
|
|
||
| Returns TcpIp protocol information for the default SQL Server instance | ||
| on the local computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscServerProtocol -ServerName 'MyServer' -InstanceName 'MyInstance' -ProtocolName 'NamedPipes' | ||
|
|
||
| Returns NamedPipes protocol information for the MyInstance SQL Server | ||
| instance on the MyServer computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscServerProtocol -InstanceName 'MSSQLSERVER' | ||
|
|
||
| Returns all protocol information for the default SQL Server instance | ||
| on the local computer. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputer -ServerName 'MyServer' | Get-SqlDscServerProtocol -InstanceName 'MyInstance' | ||
|
|
||
| Uses pipeline input from Get-SqlDscManagedComputer to retrieve all protocols | ||
| for the specified instance. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscManagedComputerInstance -InstanceName 'MyInstance' | Get-SqlDscServerProtocol -ProtocolName 'TcpIp' | ||
|
|
||
| Uses pipeline input from Get-SqlDscManagedComputerInstance to retrieve TcpIp | ||
| protocol information. | ||
|
|
||
| .INPUTS | ||
| Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer | ||
|
|
||
| A managed computer object can be piped to this command. | ||
|
|
||
| Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance | ||
|
|
||
| A server instance object can be piped to this command. | ||
|
|
||
| .OUTPUTS | ||
| Microsoft.SqlServer.Management.Smo.Wmi.ServerProtocol | ||
|
|
||
| Returns server protocol objects from SMO (SQL Server Management Objects). | ||
| #> | ||
| function Get-SqlDscServerProtocol | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')] | ||
| [CmdletBinding(DefaultParameterSetName = 'ByServerName')] | ||
| [OutputType([Microsoft.SqlServer.Management.Smo.Wmi.ServerProtocol])] | ||
| param | ||
| ( | ||
| [Parameter(ParameterSetName = 'ByServerName')] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $ServerName, | ||
|
|
||
| [Parameter(Mandatory = $true, ParameterSetName = 'ByServerName')] | ||
| [Parameter(Mandatory = $true, ParameterSetName = 'ByManagedComputerObject')] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $InstanceName, | ||
|
|
||
| [Parameter(ParameterSetName = 'ByServerName')] | ||
| [Parameter(ParameterSetName = 'ByManagedComputerObject')] | ||
| [Parameter(ParameterSetName = 'ByManagedComputerInstanceObject')] | ||
| [ValidateSet('TcpIp', 'NamedPipes', 'SharedMemory')] | ||
| [System.String] | ||
| $ProtocolName, | ||
|
|
||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'ByManagedComputerObject')] | ||
| [Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer] | ||
| $ManagedComputerObject, | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'ByManagedComputerInstanceObject')] | ||
| [Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance] | ||
| $ManagedComputerInstanceObject | ||
| ) | ||
|
|
||
| process | ||
| { | ||
| $previousErrorActionPreference = $ErrorActionPreference | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| # Set default value for ServerName if not provided | ||
| if (-not $PSBoundParameters.ContainsKey('ServerName')) | ||
| { | ||
| $ServerName = Get-ComputerName -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| if ($PSBoundParameters.ContainsKey('ProtocolName')) | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ServerProtocol_GetState -f $ProtocolName, $InstanceName, $ServerName | ||
| ) | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose -Message ( | ||
| $script:localizedData.ServerProtocol_GetAllProtocols -f $InstanceName, $ServerName | ||
| ) | ||
| } | ||
|
|
||
| switch ($PSCmdlet.ParameterSetName) | ||
| { | ||
| 'ByServerName' | ||
| { | ||
| $serverInstance = Get-SqlDscManagedComputerInstance -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| 'ByManagedComputerObject' | ||
| { | ||
| $serverInstance = $ManagedComputerObject | Get-SqlDscManagedComputerInstance -InstanceName $InstanceName -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| 'ByManagedComputerInstanceObject' | ||
| { | ||
| $serverInstance = $ManagedComputerInstanceObject | ||
| } | ||
| } | ||
|
|
||
| if ($PSBoundParameters.ContainsKey('ProtocolName')) | ||
| { | ||
| # Get specific protocol | ||
| $protocolMapping = Get-SqlDscServerProtocolName -ProtocolName $ProtocolName -ErrorAction 'Stop' | ||
|
|
||
| $serverProtocolObject = $serverInstance.ServerProtocols[$protocolMapping.ShortName] | ||
|
|
||
| $ErrorActionPreference = $previousErrorActionPreference | ||
|
|
||
| if (-not $serverProtocolObject) | ||
| { | ||
| $errorMessage = $script:localizedData.ServerProtocol_ProtocolNotFound -f $protocolMapping.DisplayName, $InstanceName, $serverInstance.Parent.Name | ||
| $errorRecord = [System.Management.Automation.ErrorRecord]::new( | ||
| [System.InvalidOperationException]::new($errorMessage), | ||
| 'SqlServerProtocolNotFound', | ||
| [System.Management.Automation.ErrorCategory]::ObjectNotFound, | ||
| $ProtocolName | ||
| ) | ||
| $PSCmdlet.ThrowTerminatingError($errorRecord) | ||
| } | ||
|
|
||
| return $serverProtocolObject | ||
| } | ||
| else | ||
| { | ||
| # Get all protocols | ||
| $allProtocolMappings = Get-SqlDscServerProtocolName -All -ErrorAction 'Stop' | ||
| $allServerProtocols = @() | ||
|
|
||
| foreach ($protocolMapping in $allProtocolMappings) | ||
| { | ||
| $serverProtocolObject = $serverInstance.ServerProtocols[$protocolMapping.ShortName] | ||
|
|
||
| if ($serverProtocolObject) | ||
| { | ||
| $allServerProtocols += $serverProtocolObject | ||
| } | ||
| } | ||
|
|
||
| $ErrorActionPreference = $previousErrorActionPreference | ||
|
|
||
| if ($allServerProtocols.Count -eq 0) | ||
| { | ||
| return $null | ||
| } | ||
|
|
||
| return $allServerProtocols | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.