Create an Azure service principal – Azure CLI | Microsoft Docs

PHOTO EMBED

Mon Apr 25 2022 22:45:33 GMT+0000 (Coordinated Universal Time)

Saved by @iamsingularity

let "randomIdentifier=$RANDOM*$RANDOM"  
servicePrincipalName="msdocs-sp-$randomIdentifier"
roleName="azureRoleName"
subscriptionID=$(az account show --query id -o tsv)
# Verify the ID of the active subscription
echo "Using subscription ID $subscriptionID"
resourceGroup="myResourceGroupName"

echo "Creating SP for RBAC with name $servicePrincipalName, with role $roleName and in scopes /subscriptions/$subscriptionID/resourceGroups/$resourceGroup"
az ad sp create-for-rbac --name $servicePrincipalName --role $roleName --scopes /subscriptions/$subscriptionID/resourceGroups/$resourceGroup
content_copyCOPY

https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli