Skip to content
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

[Bug] Get-DBAAvailabilityGroup IsPrimary returns false when a port number is passed in under $SQLInstance #5435

Closed
3 tasks done
GeorgePalacios opened this issue Apr 30, 2019 · 1 comment · Fixed by #5436
Closed
3 tasks done

Comments

@GeorgePalacios
Copy link
Contributor

GeorgePalacios commented Apr 30, 2019

  • Running latest release of dbatools
  • Verified errors are not related to permissions
  • Is this bug with Copy-DbaDatabase? You can replicate it using Backup-DbaDatabase ... | Restore-DbaDatabase ...

Environmental data

### PowerShell version:

Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
PSVersion                      5.1.17134.590                                                                                                                                                             
PSEdition                      Desktop                                                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                   
BuildVersion                   10.0.17134.590                                                                                                                                                            
CLRVersion                     4.0.30319.42000                                                                                                                                                           
WSManStackVersion              3.0                                                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                                                       
SerializationVersion           1.1.0.1                                                                                                                                                                   




### dbatools Module version:


Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\0.9.815\dbatools.psd1
Version : 0.9.815

SQL Server:

/* Microsoft SQL Server 2014 (SP2-CU9) (KB4055557) - 12.0.5563.0 (X64)   Dec  7 2017 01:00:06   Copyright (c) Microsoft Corporation  Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor) */

Errors Received

No errors recieved

Steps to Reproduce

<#
    Get-DBAAvailabilityGroup -IsPrimary -SQLInstance "SERVERNAME,1234"
#>

Expected Behavior

Actual Behavior

@GeorgePalacios
Copy link
Contributor Author

GeorgePalacios commented Apr 30, 2019

I have found the issue in the code. Line 102

Add-Member -Force -InputObject $ag -MemberType NoteProperty -Name IsPrimary -Value ($ag.PrimaryReplicaServerName -eq $server.Name)

The assertion $ag.PrimaryReplicaServerName -eq $server.Name fails when the $SQLInstance parameter contains a port number, as the $server.Name property does not contain the port number. The end result is that $ag.PrimaryReplicaServerName and $server.Name never match.

A potential fix would be to change this to ($ag.LocalReplicaRole -eq "Primary")

@GeorgePalacios GeorgePalacios changed the title [Bug] Get-DBAAvailabilityGroup IsPrimary returns false [Bug] Get-DBAAvailabilityGroup IsPrimary returns false when a port number is passed in under $SQLInstance Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant