Powershell script to enable Microsoft.SQL service endpoint and add to Azure SQL

Jeff Fazio 36 Reputation points
2024-08-05T14:08:11.1366667+00:00

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.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,251 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,517 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.