Use Azure Powershell to execute .sql file

I saw examples of running an SQL command from Azure Powershell, for example.

$connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90" $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString) $query = "CREATE TABLE...." $command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection) $connection.Open() $command.ExecuteNonQuery() $connection.Close() 

Is there a way to replace the $ request with a link to an external file containing the entire SQL script?

Thanks.

+6
source share
1 answer

Another 20 minutes of searching, and I found it.

 $connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90" $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString) $query = [IO.File]::ReadAllText("C:\...\TestSQL.sql") $command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection) $connection.Open() $command.ExecuteNonQuery() $connection.Close() 
+7
source

Source: https://habr.com/ru/post/985607/


All Articles