Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active April 11, 2016 23:31
Show Gist options
  • Save justinyoo/ea1237b06e463e030f6cf072f2a6e878 to your computer and use it in GitHub Desktop.
Save justinyoo/ea1237b06e463e030f6cf072f2a6e878 to your computer and use it in GitHub Desktop.
DevOps Pro Tip - Creating Accounts on Azure SQL Database through PowerShell
$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