Skip to content

Commit d392597

Browse files
committed
docs: add sql function post
1 parent 4d4792f commit d392597

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: post
3+
title: Set specific database role permissions Azure SQL
4+
categories: powershell azure sql rbac
5+
---
6+
7+
## Introduction
8+
9+
I had to set permissions on multiple databases on an Azure SQL server.
10+
I decided to create a function for this that can set specific database role permissions on all or one SQL database within an Azure SQL server.
11+
12+
![Azure SQL](../assets/images/post_2024-04_azureSql.png){:width="50%"}
13+
14+
The script uses sqlcmd to connect to the Azure SQL server and configure the permissions. So apart from PowerShell, you will need to have the Az.Accounts PowerShell module and the SqlServer PowerShell module installed.
15+
Or you can automate it even further by using an Azure DevOps pipeline or GitHub action that first installs PowerShell and the required modules.
16+
17+
Of course you need to either connect using the Sql administrator account or the Microsoft Entra admin for Azure Sql. (The Entra admin can also be a security group in Entra Id)
18+
19+
SqlCmd is very picky about quotes, especially if your Entra ID group has spaces, so the script does some replacing of single quotes (') with two single quotes ('').
20+
21+
## The script
22+
23+
Without further ado, here's the script:
24+
25+
{% gist MarcoJanse/f78534f8d22a9b215a476a122ac5e6aa %}
26+
27+
## Closing notes
28+
29+
I hope someone will make good use of this script or make it even better.
30+
31+
## References
32+
33+
- [Authorize database access to SQL Database, SQL Managed Instance, and Azure Synapse Analytics \| Microsoft Learn](https://learn.microsoft.com/en-us/azure/azure-sql/database/logins-create-manage?view=azuresql)
6.76 KB
Loading

0 commit comments

Comments
 (0)