-
-
Save justinyoo/ea1237b06e463e030f6cf072f2a6e878 to your computer and use it in GitHub Desktop.
DevOps Pro Tip - Creating Accounts on Azure SQL Database through PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$server = "tcp:my-azure-sql.database.windows.net,1433" | |
$database = "MyDatabase" | |
$adminName = "admin@my-azure-sql" | |
$adminPassword = "P4SSW0rd" | |
$connectionString = "Server=$server;Database=$database;User ID=$adminName;Password=$adminPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | |
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString) | |
$queryPath = "C:\Temp\SqlDbo.sql" | |
$query = [System.IO.File]::ReadAllText($queryPath) | |
$command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection) | |
$username = New-Object -TypeName System.Data.SqlClient.SqlParameter("@Username", "MyDboName") | |
$command.Parameters.Add($username) | |
$connection.Open() | |
$command.ExecuteNonQuery() | |
$connection.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment