Skip to content

Connection to SQL in Azure broken following latest Az module update #9679

Open
@emhansonoh

Description

@emhansonoh

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

After update to the latest Az (Azure) powershell module - the ability to connect to an Azure SQL Managed Instance has broken. When you issue the Get-AzAccessToken, starting with module version 14 - the value was changed from a plain text String to SecureString per their documentation (https://learn.microsoft.com/en-us/powershell/module/az.accounts/get-azaccesstoken?view=azps-14.0.0).

From everything I've found - Connect-DbaInstance does not currently support the ability to pass a SecureString. Attempted to connect does result in an authentication failure.

Error connecting to [YOUR-AZURE-SQL-MANAGED-INSTANCE.database.windows.net]: Login failed for user ''.

This is reproduced by using the latest Az module along with the latest dbatools module

  1. Connect-AzAccount
  2. $azureToken = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token
  3. $azureInstance = "YOUR-AZURE-SQL-MANAGED-INSTANCE.database.windows.net"
  4. $server = Connect-DbaInstance -SqlInstance $azureInstance -Database "YOURDATABASE" -AccessToken $azureToken

Steps to Reproduce

# provide your command(s) executed pertaining to dbatools
# please include variable values (redacted or fake if needed) for reference

Connect-AzAccount
$azureToken = (Get-AzAccessToken -ResourceUrl https://database.windows.net).token/
$azureInstance = "YOUR-AZURE-SQL-MANAGED-INSTANCE.database.windows.net"
$server = Connect-DbaInstance -SqlInstance $azureInstance -Database "YOURDATABASE" -AccessToken $azureToken

Please confirm that you are running the most recent version of dbatools

DBATools --> 2.1.31
Az --> 14.0.0

Other details or mentions

This worked as expected with prior module (13.5.0)

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name Value


PSVersion 7.4.7
PSEdition Core
GitCommitId 7.4.7
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

SQL Server Edition and Build number

Microsoft SQL Azure (RTM) - 12.0.2000.8 Apr 1 2025 12:07:14 Copyright (C) 2022 Microsoft Corporation

.NET Framework Version

.NET 8.0.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions