Skip to content

Commit

Permalink
docs: add sql function post
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoJanse committed Apr 5, 2024
1 parent 4d4792f commit d392597
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
layout: post
title: Set specific database role permissions Azure SQL
categories: powershell azure sql rbac
---

## Introduction

I had to set permissions on multiple databases on an Azure SQL server.
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.

![Azure SQL](../assets/images/post_2024-04_azureSql.png){:width="50%"}

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.
Or you can automate it even further by using an Azure DevOps pipeline or GitHub action that first installs PowerShell and the required modules.

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)

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 ('').

## The script

Without further ado, here's the script:

{% gist MarcoJanse/f78534f8d22a9b215a476a122ac5e6aa %}

## Closing notes

I hope someone will make good use of this script or make it even better.

## References

- [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)
Binary file added docs/assets/images/post_2024-04_azureSql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d392597

Please sign in to comment.