Powershell script to enable Microsoft.SQL service endpoint and add to Azure SQL
We have certain VM's that need to be able to access Azure SQL. Since allow public access is turned off, I need to add the Virtual Network/Subnet to SQL Instance. Then also, I need to enable Microsoft.SQL for the service endpoint on any of the subnets with the VM's.
Since this could get missed during the build process, I was thinking of creating an Automation that will check a few times a day to make sure all the subnets in a Virtual have the Microsoft.SQL service endpoint enabled. I have this part setup and works fine.
I guess is there a way in to create a script so that if Subnet A is in VirtualNetwork 1 then check to make sure Microsoft.SQL is enabled and it's been added to SQLServer Virtual Network list to be allowed. If not, then add it.
I think a problem is going to be that Automation can only be run on the subscription it's created in.
If anyone has any ideas, that would be great.