Azure automation account sqlcmd

sakuraime 2,321 Reputation points
2021-02-18T06:14:43.35+00:00

I would like to use invoke-sqlcmd in azure automation account . using option -query

I declare a query (multi line query)

$query = @'

declare @var1 varchar(10)
declare @var2 varchar(10)...... and some other TSQL
'@

then

invoke-sqlcmd -ServerInstance "servername" -Database "dbname" -Credential $SQLServerCred -Query "$Query" -Encrypt

however it's failed to run the job .

why ??

I don't want to use store procedure , as I will need to create the same store procedure at different Azure sql database .

any other possible solution ?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,310 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,188 questions
{count} votes

1 answer

Sort by: Most helpful
  1. sakuraime 2,321 Reputation points
    2021-02-18T09:51:03.893+00:00

    thanks. I finally figure out the issue

    it's should be some syntax problem. Thanks