How to connect Azure Paas Database using Powershell with intergrated security How to connect Azure Paas Database using Powershell with intergrated security powershell powershell

How to connect Azure Paas Database using Powershell with intergrated security


You could use Azure AD account to login Azure SQL database(Paas) by using Azure Active Directory Authentication. More information please refer to this link.

Note: Local domian AD user does not support this.

You could use following script to login with Azure AD authentication.

#You admin Azure AD user name$Username = "shuitest@*****.onmicrosoft.com"$Password = "********"$Database = "testg"$Server = 'test.database.windows.net'$Port = 1433$cxnString = "Server=tcp:$Server,$Port;Database=$Database;Authentication=Active Directory Password;UID=$UserName;PWD=$Password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"$query = "select count(*) from dbo.Authors"$cxn = New-Object System.Data.SqlClient.SqlConnection($cxnString)$cxn.Open()$cmd = New-Object System.Data.SqlClient.SqlCommand($query, $cxn)$cmd.CommandTimeout = 120$cmd.ExecuteNonQuery()$cxn.Close()


The following sample shows how to invoke Add-AzureAccount without the popup dialog:

$username = "someorgid@orgaccount.com"$password = "Pa$$w0rd" | ConvertTo-SecureString -AsPlainText -Force$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password Add-AzureAccount -Credential $credential 


AAD does not / can not parse Kerbs tokens. In order to get integrated auth to work from your desktop, you need to have ADFS (or similar) in your environment. That way your desktop will authenticate against AAD, redirect to ADFS, and your kerbs token will be recognized.

See https://docs.microsoft.com/en-us/azure/sql-database/sql-database-aad-authentication for more information.