I'm trying to create a deploy script in powershell to create and configure the environment for a web application. The web app uses user-assigned Managed Identity to reach the SQL server.
I have to run the following command in the SQL server:
CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
But this command errors when I use sql adminstrator login: "Only connections established with Active Directory accounts can create other Active Directory users."
I add an AD administrator with Set-AzSqlServerActiveDirectoryAdministrator
But how can use this AD login from powershell to run the SQL command?
Invoke-Sqlcmd -Database "$($sqlDBName)" -ServerInstance "$($sqlServerName).database.windows.net" -Username "$($dbuser)" -Password "$($dbpw)" -OutputSqlErrors $true -Query "CREATE USER [managed_id] FROM EXTERNAL PROVIDER;"