title: How to execute SQL in a PowerShell script as part of a Visual Studio Team Services build task?
body: <p>How to execute SQL against an Azure SQL database as part of a PowerShell script in a VSTS build task in a hosted agent?</p>
  
  <p>There are many tasks available for build definitions: we can execute a PowerShell script</p>
  
  <p><a href="https://i.stack.imgur.com/SKJc9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SKJc9.png" alt="enter image description here"></a></p>
  
  <p>or deploy SQL using DACPAC or SQLCMD</p>
  
  <p><a href="https://i.stack.imgur.com/eIwZ9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eIwZ9.png" alt="enter image description here"></a></p>
  
  <p>or even execute PowerShell on remote machines</p>
  
  <p><a href="https://i.stack.imgur.com/E6sMi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6sMi.png" alt="enter image description here"></a></p>
  
  <p>but how to simply execute SQL as part of a PowerShell script?
  Invoke-Sqlcmd isn't available as part of the 'Azure PowerShell' task.</p>
  
  <p>I guess it would be possible to remote desktop to an app service, install the SQL Server related bits there and use 'PowerShell on Target Machines' but I feel there has to be a simpler way - perhaps I'm just missing something obvious</p>