-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
initial commit of Get-DbaAvailabilityGroup #251
initial commit of Get-DbaAvailabilityGroup #251
Conversation
@ClaudioESSilva do you have an environment to support testing for this command? If so, would you be available to do so this week? Here is the QA checklist
|
@ctrlbold I have and I am. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main decision is if we go and use multi server or not and dynamic parameters
Param ( | ||
[parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[Alias("ServerInstance", "SqlInstance")] | ||
[object]$SqlServer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this command supports mutiple servers?
I vote yes. I want be able to do something like @('server1', 'server2') | Get-SqlAvailabilityGroup
.
If yes this should be an array [object[]]$SqlServer
and we have to add foreach loop on process moving the code inside begin block to there.
[switch]$IsPrimary | ||
) | ||
|
||
# DynamicParam { if ($sqlserver) { return Get-ParamSqlDatabases -SqlServer $sqlserver -SqlCredential $SqlCredential } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need help with this?
Change to:
DynamicParam { if ($sqlserver) { return Get-ParamSqlAvailabilityGroups -SqlServer $sqlserver -SqlCredential $SqlCredential } }
And add this block code to DynamicParams.ps1 files
Function Get-ParamSqlAvailabilityGroups
{
<#
.SYNOPSIS
Internal function. Returns System.Management.Automation.RuntimeDefinedParameterDictionary
filled with ProxyAccounts from specified SQL Server Job Server (SQL Agent).
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("ServerInstance","SqlInstance")]
[object]$SqlServer,
[System.Management.Automation.PSCredential]$SqlCredential
)
try { $server = Connect-SqlServer -SqlServer $SqlServer -SqlCredential $SqlCredential -ParameterConnection }
catch { return }
$list = @()
# Populate arrays
$list = $server.AvailabilityGroups.Name
# Reusable parameter setup
$newparams = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$attributes = New-Object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = "__AllParameterSets"
$attributes.Mandatory = $false
$attributes.Position = 3
# Database list parameter setup
if ($list) { $validationset = New-Object System.Management.Automation.ValidateSetAttribute -ArgumentList $list }
$attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributeCollection.Add($attributes)
if ($list) { $attributeCollection.Add($validationset) }
$AvailabilityGroups = New-Object -Type System.Management.Automation.RuntimeDefinedParameter("AvailabilityGroups", [String[]], $attributeCollection)
$newparams.Add("AvailabilityGroups", $AvailabilityGroups)
$server.ConnectionContext.Disconnect()
return $newparams
}
[object]$SqlServer, | ||
[object]$SqlCredential, | ||
[switch]$Detailed, | ||
[string]$AvailabilityGroupName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we will support dynamic param, this one should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until fix is in place where dynamic parameters actually show up in help, I don't use them. Considering this would likely be a parameter that will/should get used I don't care to have it hidden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix is coming this month, but I would prefer that we try to be as standardized as possible and always try to support DynamicParams when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the measure or test that passes to say dynamic parameters should be used?
I would also wonder where will dynamic parameters work? Examples I see folks using is in ISE, which I don't use. So do they work on the command line (support tab completion)?
{ | ||
if (!$server.IsHadrEnabled) | ||
{ | ||
Return "Availability Group is not configured." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runned against SQL Server lower than 2012 (when AG feature appears) and the message is "Availability Group is not configured."
I suggest to validate server major version and if lower than 11 then say something like "Availability Groups is available only on SQL Server 2012 (v11) or higher versions. Server '$server' has version $($server.Major). Skipping."
We can validate the edition, too. AG is only available on Enterprise Edition so if running on, for example, Standard Edition should say "Availability Groups feature is only available on Entrepise edition. Server '$Server' is running '$server.Edition'. Skipping."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, being that Connect-SqlServer was going to be updated to have the version flags, figured wait until that is done. Instead of duplicating code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like this to be standard as well. It helps because I can do mass finds and replaces. In addition, it's part of the QA checks that we gotta check.
[object]$SqlCredential, | ||
[switch]$Detailed, | ||
[string]$AvailabilityGroupName, | ||
[switch]$IsPrimary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this parameter needs the $AvailabilityGroupName and if we don't use dynamic parameters, we should set a PARAMETERSET which enforce the mandatory of both parameters.
If we will use dynamic parameter maybe we should validate this on the beginning of the Process instead after get all the info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already tried that and it does not work correctly but also IsPrimary should not be a required parameter if someone wants to pull back specific AG info.
…tools into NewCommand-Get-DbaAvailabilityGroup
Sorry for the delay @wsmelton, gotta build a new AG cluster to test. But at least I'll finally have AGs in the lab again 💃 |
…tools into NewCommand-Get-DbaAvailabilityGroup
…fied output for IsPrimary, addtion of switches for -simple, -detailed. - Added check for major version, throw error if less than 11 (SQL Server 2012)
Initial commit