DEV Community

Cover image for My first Powershell Azure Function
Antoine
Antoine

Posted on

My first Powershell Azure Function

Photo by Tim Mossholder on Unsplash

I'm mostly a C# developer. Lastly, i had to programmatically modify an Azure Web application to add or remove firewall rules in a Web application and a SQL one.
To me, it was obvious to use:

It was easy for the SQL part.
but i was stuck for the Web application part, as the firewall rules was part of the inner configuration of the web application.

It was a surprise to me as the Powershell Core command was pretty simple to use.
So i was gladly surprised to see powershell function available, and the experience is simple.

Modules

I just need Az modules to complete my task. In order to check which modules are available, i just have to insert those lines in the function:

Get-Module -ListAvailable | Select-Object Name, Version | Sort-Object -Property Name
Enter fullscreen mode Exit fullscreen mode

Az modules are here, so nothing to install.

Identity

For the authentication / authorization part, i rely on a Managed Service Identity, and on role based authorization control (RBAC) on the Web application.

In order to connect and i have the right identity i just have to:

Connect-AzAccount -Identity
$az = Get-AzContext
write-host $az
Enter fullscreen mode Exit fullscreen mode

Command to execute

I just have to execute the command to add the access :

Add-AzWebAppAccessRestrictionRule
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Top comments (0)