Skip to content

Instantly share code, notes, and snippets.

@ralacher
Last active May 8, 2024 06:56
Show Gist options
  • Save ralacher/000a6fb73d5d0e042c2cb0eb713079ec to your computer and use it in GitHub Desktop.
Save ralacher/000a6fb73d5d0e042c2cb0eb713079ec to your computer and use it in GitHub Desktop.
Azure CLI Cheat Sheet

Az CLI

Collection of commands I've found useful and don't want to forget or lose from my shell history.

Account

# Set the context
az account set -s $subscriptionName
# Show context information
az account show
# Login with a service principal
az login --service-principal --username $clientId --password $clientSecret --tenant $tenantId

Active Directory

# Show a user
az ad user show --id $mail --query "displayName"
# Show a group
az ad group show -g $groupName --query "objectId"
# List group members
az ad group member list -g $groupName --query "[].displayName"
# List service principals
az ad sp list --display-name "Startswith..." --query "[].[displayName,objectId]"

DevOps

# List projects
az devops project list --organization $orgUrl --query "value[].name" > projects
# List repositories
while read project; do az repos list --detect true --organization $orgUrl --project $project --query "[].{repoName: name,projectName: pr
oject.name}" >> repo_list; done < projects

Extensions

az extension add --name $extensionName

Azure PowerShell

Account

# Set context
Set-AzContext -Subscription $SubscriptionName
# Get context
Get-AzContext

Custom RBAC roles

# Get role definition
$Role = Get-AzRoledefinition -Name $RoleName
# Modify permissions
$Role.Actions.Add("Microsoft.Compute/...")
$Role.Actions.Remove("Microsoft.Compute/...")
# Update role
Set-AzRoleDefinition -Role $Role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment