Create a Service Principal in Azure using PowerShell

Create a Microsoft Azure Service Principal using PowerShell. It enables you to assign permissions to the app identity. We will assign API permissions. 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 to Microsoft Documentation.



Steps to create Service Principal

Note: This demo will use Windows operating system.

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

az --version

If you don’t see the 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

The default browser will ask for 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 the 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.

Leave a Reply

Up ↑

%d bloggers like this: