I am working on ARM template to setup SQL server VM on Azure with Always on High availibility setup using Win server 2019 and SQL Server 2019 Enterprise image. I am trying to automate everything using ARM template. Now, I need to execute SETSPN commnad on one of the Azure SQL Server VM using AMR template for which I used Script Deployment template and there using Invoke-AzVMRunCommand command to run PowerShell script on Azure VM. As Invoke-AzVMRunCommand run PowerShell script with System Account context, I am getting access denied error when SETSPN command try to execute on the remote VM. So, looking for any other option to run PowerShell command to Azure VM in automated way with domain user context having permission to execute SETSPN command. Here is the command I am trying to execute on VM using ARM deployment script and Invoke-AzVMRunCommnad.

setspn -S MSSQLSvc/..com:1433 domain\sqlserviceaccount

1 Answer 1


I'm not sure why using setspn as System isn't a valid thing for you to do, but if you want to use a domain user you'll need to store creds in the automation account and setup a hybrid runbook worker. It's kind of a pain.

  • 1
    thank you for your answer and welcome to DBA stack Exchange. Your answer would be much more appreciated if you added more details and\or links to clarify what is and how to store creds in the automation account or what is a hybrid runbook and how it works. Oct 18, 2022 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.