Create a Service Principal in Azure using PowerShell

This is part 1 of the series “Create Azure Resource Manager Bot

When you have an app or script that needs to access resources, you can set up an identity for the app and authenticate the app with its own credentials. This identity is known as a service principal. This approach enables you to assign permissions to the app identity that are different than your own permissions. Typically, these permissions are restricted to exactly what the app needs to do.

For more information, refer Microsoft Documentation.



Steps to create Service Principal

Note: This demo will use Windows operating system.

Launch Windows PowerShell and type following command to check if Azure CLI is installed.

az --version

If you don’t see azure-cli version or get an error “az not recognized” then reinstall Azure CLI and restart the PowerShell. Login to your Azure account using the below command.

az login

Default browser will ask your login details. Once successful login following Azure details will be shown.

Set your active subscription using the below command.

az account set --subscription "<Subscription ID>"

Subscription ID can be found in the previous response after you logged in. Create service principal using following command.

az ad sp create-for-rbac -n "<Name of Service Principal>"

You can also check your Service principal in Azure Active Directory -> App Registration

Thank you!!! Hope you find this useful.

Up ↑

%d bloggers like this: