How to fix when quoting user information from Azure with powershell.

N.I 0 Reputation points
2023-07-07T07:45:12.24+00:00

I want to connect to Azureserver from a powershell command.

An error occurs when executing the following sql.

The target Azure user has been created.

"FROM EXTERNAL PROVIDER" is an error.

how to fix when citing user information from azure.

sql:CREATE USER [username] FROM EXTERNAL PROVIDER;

error:

invoke-sqlCmd : Principal 'username' could not be created. Only connections established with Active Dir

ectory accounts can create other Active Directory users.

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Stan Frambach 41 Reputation points
    2023-07-07T08:00:48.99+00:00

    When you specify FROM EXTERNAL PROVIDER in your command you are adding an Azure Active Directory user. If you want to add an AD user you can only do so while signed into an AD account. So option 1:

    Use an Active Directory account: Make sure you are using an Active Directory account to connect to Azure SQL Database from PowerShell. You can use the "Connect-AzAccount" cmdlet to authenticate with your Azure AD account before executing the SQL statement.

    Option 2: just create a local SQL account:

    "CREATE USER [username] WITH PASSWORD = 'password';"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.