Skip to content

Instantly share code, notes, and snippets.

@cerealskill
Last active December 26, 2017 19:22
Show Gist options
  • Select an option

  • Save cerealskill/fb288d848fe46abcd0ba53cfefc2a8f0 to your computer and use it in GitHub Desktop.

Select an option

Save cerealskill/fb288d848fe46abcd0ba53cfefc2a8f0 to your computer and use it in GitHub Desktop.
PowerShell Execute Procedure on webjobs in WebApps (Azure)
Write-Output "JOB START"
# Create connection to Master DB
$MasterDatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$MasterDatabaseConnection.ConnectionString = "Data Source=_DBNAME_.database.windows.net;Initial Catalog=_DBCATALOG_;Integrated Security=False;User ID=_USERDB_;Password=_PASSDB_;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"
$MasterDatabaseConnection.Open()
Write-Output "CONNECTION OPEN"
# Create command
$MasterDatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$MasterDatabaseCommand.Connection = $MasterDatabaseConnection
$MasterDatabaseCommand.CommandText = "_NAME_PROCEDURE_TO_EXECUTE_"
Write-Output "DATABASE COMMAND TEXT ASSIGNED"
# Execute the query
$MasterDatabaseCommand.ExecuteNonQuery()
Write-Output "EXECUTING QUERY"
# Close connection to Master DB
$MasterDatabaseConnection.Close()
Write-Output "CONNECTION CLOSED"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment