Is there any Option to execute below SQL query's using PowerShell?

369 views Asked by At

The below mentioned SQL queries we are doing manually using the Query Editor in Azure Portal SQLDB. But, we have to execute these using the PowerShell, and I was went through the couple of articles and unable to find a exact solution to perform this action. If any one have PowerShell script handy, can you guys please.... help!

  1. Login to SQL Database using Admin login.

  2. Execute the following commands.

    CREATE USER [App Service Name] FROM EXTERNAL PROVIDER;
    ALTER ROLE db_datareader ADD MEMBER [App Service Name];
    ALTER ROLE db_datawriter ADD MEMBER [App Service Name];

1

There are 1 answers

3
SE1986 On

This is a simple Invoke-SqlCmd call:

Invoke-Sqlcmd -ServerInstance "YourServer" -Database master -Query "CREATE USER [App Service Name] FROM EXTERNAL PROVIDER; ALTER ROLE db_datareader ADD MEMBER [App Service Name]; ALTER ROLE db_datawriter ADD MEMBER [App Service Name];"