PS cmdlet : Add-SqlAzureAuthenticationContext connect to Azure China - sql-server

I have a working script via https://learn.microsoft.com/en-us/sql/relational-databases/security/encryption/configure-always-encrypted-keys-using-powershell (KeyVault + SQL Azure setup), in "Step 6. Authenticate to Azure, if your column master key is stored in Azure Key Vault.", I run PS "Add-SqlAzureAuthenticationContext -Interactive", but this will pop a dialog connect to Azure US,not Azure CN.
I browsed cmdlet doc, cannot see anything setting environment parameter, how can I let the cmdlet connect to AzureCN?
Thanks,
Cheng

Related

AAD connect provisioning credentials

How can I find the credentials for this?
Please see image below.
I Tried to reproduce the same in my environment to connect using GMSA
First install ACTIVE DIRECTORY DOMAIN SERVICES and create service account for windows server using the below powershell.
Before executing the powershell script, kindly create one Security name GMSA-Test
PrincipalsAllowedToRetrieveManagedPassword is Security Group Name
Import-module ActiveDirectory
Add-KdsRootKey -EffectiveTime ((get-date).addhours(-10))
New-ADServiceAccount <youraccountname> -DNSHostName ITFarm1.contoso.com -PrincipalsAllowedToRetrieveManagedPassword <GMSA-Test> -KerberosEncryptionType RC4, AES128, AES256 -ServicePrincipalNames http/ITFarm1.contoso.com/contoso.com, http/ITFarm1.contoso.com/contoso, http/ITFarm1/contoso.com, http/ITFarm1/contoso
get-ADServiceAccount GMSAtest
Install ADServiceAccount using powershellon AAD Connect Server
Install-ADServiceAccount -Identity <youraccountname>
successfully created service account after ran the powershell commands.
Configure AAD connect with your Service Account.
Service Account Name: your domain\GMSAtest$
Password: PrincipalsAllowedToRetrieveManagedPassword
Reference: Using Azure AD Connect with a gMSA - The things that are better left unspoken (dirteam.com)

Authenticate to SQL Server through PowerShell with MFA (Active Directory Interactive)

I am trying to set up a PowerShell script to enable Always Encrypted on our Azure SQL Server databases. I am following this guide, which offers the following sample code:
# Import the SqlServer module
Import-Module "SqlServer"
# Connect to your database
# Set the valid server name, database name and authentication keywords in the connection string
$serverName = "<Azure SQL server name>.database.windows.net"
$databaseName = "<database name>"
$connStr = "Server = " + $serverName + "; Database = " + $databaseName + "; Authentication = Active Directory Integrated"
$database = Get-SqlDatabase -ConnectionString $connStr
# List column master keys for the specified database.
Get-SqlColumnMasterKey -InputObject $database
I run into problems however with getting the database connection to work. From what it seems the Get-SqlDatabase command from the SqlServer module that is used does not seem to support login through MFA. Our company have enforced this type of login, so I can't seem to find a way around this.
When running Get-SqlDatabase -ConnectionString 'Server=myserver.database.windows.net; Database=myDB; Authentication=Active Directory Interactive;' I receive the following error:
Cannot find an authentication provider for 'ActiveDirectoryInteractive'.
Does SqlServer-module lack the ability to support MFA logins? Or am I missing something else?
Get-SqlDatabase Cmdlet uses the System.Data.SqlClient wherein as per the documentation below values are supported in Authentication Keyword.
Valid values are:
Active Directory Integrated
Active Directory Password
Sql Password
Active Directory Integrated :To use This authentication mode can be, you need to federate the on-premise Active Directory Federation Services (ADFS) with Azure Active Directory in the cloud
Active Directory Password: authentication=ActiveDirectoryPassword can be used to connect to an Azure SQL Database/Synapse Analytics using an Azure AD user name and password.
Sql Password :Use authentication=SqlPassword to connect to a SQL Server using userName/user and password properties.
If you want to Authenticate to Sql Server through PowerShell with MFA you need to use Active Directory Interactive in authentication keyword which is not supported by system.data.sqlclient
Active Directory Interactive:authentication=ActiveDirectoryInteractive can be used to connect to an Azure SQL Database/Synapse Analytics using an interactive authentication flow (multi-factor authentication)
Please note that the System.Data.SqlClient driver, and consequently the Get-SqlDatabase cmdlet, does not support the full range of Azure AD authentication methods. If none of the supported methods works in your environment, using SQL authentication may be the only option.

Connect to Azure SQL database using SSMS via AAD MFA when account is guest of another directory

I have a problem when connecting to an Azure SQL Database using SSMS under this scenario:
Have a work laptop connected to work domain via VPN
The database is in a different Azure tenant (tenant B) to my work Azure tenant
(tenant A).
My work account is set up via AAD in the work Azure tenant (A)
and is a guest account in other tenant (B)
Have the latest version of SSMS
Granted user access to the Azure SQL database
I connect via SSMS using the Azure Active Directory - Universal
with MFA option
Note all default options are set and have also tried setting the database
I know the database access has been correctly set up as I have successfully been able to connect in the above scenario when I use Azure Data Studio instead of SSMS, but only because I have the option to change "Azure AD tenant" property from "Tenant A" to "Default Directory".
I have been able to connect OK when using SSMS with my personal computer using the same account / method, except it is not using a work account and is not connected to the work domain.
Seems like my issue is that I cannot change the "Azure AD tenant" property in SSMS and it is using the tenant associated with my account. I have also tested with a number of different people and they have the same issue. I have also set the default Azure directory to tenant B in the Azure portal.
Does anyone have any suggestion how I can get this to work in SSMS?
Azure Data Studio connection
Thanks Tony
OK, I am answering my own question.
I have a work-around which involves:
Create a connection in Azure Data Studio and setting the Azure AD Tenant to "default directory"
In SSMS, connect to the Database using the Azure Data Studio connection in the Registered Servers pane
Not ideal, but it works.

Connect to Azure database with DataGrip - Active Directory

I am trying to connect to Azure database via DataGrip using Active Directory connection (Note: not Active directory - password)
I followed accepted answer from this
I set integratedSecurity=false and authentication=ActiveDirectoryIntegrated.
When trying to connect to Test Connection I get error message
Connection to Azure SQL Database failed. Cannot set "Authetication" with "IntegratedSecurity" set to "true".
Is it some kind of bug that can be repaired, if so how could I solve this issue?
Edit:
More information:
On Azure Portal I can see that this is SQL database.
Server name ends with database.windows.net.
When I try to connect via Connection String (in Data Grip Add data from URL) generated by Azure I am not able to connect also.
The DataGrip support us using Azure Active Directory Authentication. Please see: Microsoft Azure .
You can get the connect string (URL) with Active Directory integrated authentication from Portal:
Replace the URL with the Connect string(Active Directory integrated authentication):
Hope this helps.
There is a lot of confusion around terminology here.
In short, the connection string attribute Integrated Security=true indicates you want to use "windows authentication". This type of authentication might be supported by any Azure SQL (anything whose hostname ends in database.windows.net). Azure SQL only supports Azure Active Directory authentication, butit might be possible to implement single sign on between a windows domain account and Azure Active Directory.

PowerShell: Changing MS SQL Server Login User Mapping

I need to modify the User Mapping of a specific MS SQL Server Login using PowerShell. I need the Login to map to a specific database, while also selecting db_owner as a Database role membership. The only piece of code I have so far is code that will connect to MS SQ Server.
$svc_Obj = Get-WmiObject Win32_Service -filter "name='MSSQLSERVER'"
However, I'm not sure how I would be able to modify the Login's User Mapping with this. Could someone show me how to do this with either this code or with something else?
There are lots of examples all over the web on how to do this. A quick search using you favorite engine, using your posts' heading would give you a decent list on the topic. Even searching directly on this site, would give you a decent list.
For example:
Connect to SQL Server Database from PowerShell
I have looked around online for a while now and found many similar
problems but for some reason I can't seem to get this working.
I am just trying to connect to a SQL server database and output the
query results to a file - See PowerShell script below. What I am
uncertain about is how to integrate the User ID and Password into the
connection string.
Connect to SQL Server Database from PowerShell
Powershell - User Mapping SQL Server 2012
I am trying to script User Mapping for different Login accounts. I
have scripted the creation of users and individual server roles, but I
can't figure out how to set User Mapping with Powershell, I will also
need to set the Database Role membership, in Particular,
db_backupoperator
Powershell - User Mapping SQL Server 2012
Connect to SQL Server via Windows PowerShell with SQL Server
authentication
Problem In previous tips on Windows PowerShell with SQL Server, you've
seen how you can use Windows PowerShell and SMO to administer SQL
Server databases. Most of the examples have used Windows
authentication to connect to SQL Server. How can I connect to SQL
Server via Windows PowerShell using mixed mode authentication?
https://www.mssqltips.com/sqlservertip/1947/connect-to-sql-server-via-windows-powershell-with-sql-server-authentication/
SQL Server: Change the Login Password using PowerShell
Here’s a quick Article detailing a PowerShell script that can be used
to change the password for a SQL Server Login.
https://social.technet.microsoft.com/wiki/contents/articles/22767.sql-server-change-the-login-password-using-powershell/rss.aspx

Resources