sql server - How to run a SQL batch within an Azure runbook? -
i need execute batch perform maintenance tasks in database examples on azure automation see dealing a single sql command.
how do if creating sp not option? think need either somehow embed script.sql file runbook script or reference (like here, example)?
you store .sql file in azure blob storage, , within runbook download .sql file, read contents, , pass sqlcommand object.
something like:
try { # connect azure using service principal auth $serviceprincipalconnection = get-automationconnection -name $azureconnectionassetname write-output "logging in azure..." $null = add-azurermaccount ` -serviceprincipal ` -tenantid $serviceprincipalconnection.tenantid ` -applicationid $serviceprincipalconnection.applicationid ` -certificatethumbprint $serviceprincipalconnection.certificatethumbprint } catch { if(!$serviceprincipalconnection) { throw "connection $azureconnectionassetname not found." } else { throw $_.exception } } $path = "c:\abc.sql" set-azurermcurrentstorageaccount -resourcegroupname $resourcegroupname -name $storageaccountname get-azurestorageblobcontent -container $container -blob $blob -destination $path $content = get-content $path $cmd = new-object system.data.sqlclient.sqlcommand($content, $conn)
Comments
Post a Comment