Skip to content

petitess/azcli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://learn.microsoft.com/sv-se/cli/azure/service-page/azure%20cli?view=azure-cli-latest

login

az account show
az account list
az login
az logout
$SubId = az account subscription list --query "[?displayName=='sub-infra-dev-01' && state=='Enabled'].id" -o tsv
$SubName = az account subscription list --query "[?displayName=='sub-infra-dev-01'].displayName" -o tsv
az account set --name $SubName

az login --service-principal -u $env:client_id -p $env:client_secret --tenant $env:tenant_id
$Token = az account get-access-token --scope "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default" --query accessToken --output tsv
$URL = "https://adb-abc.azuredatabricks.net/api/2.0/clusters/list"
$Headers = @{
    "Authorization" = "Bearer $Token"
    "Content-type" = "application/json"
}
Invoke-RestMethod -Method GET -URI $URL -Headers $Headers

deployment

$subName = "sub-xxx-test-01"
$subId = az account list --query "[?name=='$subName'].id" -o tsv
$Timestamp = Get-Date -Format 'yyyy-MM-dd'
az deployment sub 'create' `
    --name "Deploy_$Timestamp" `
    --subscription $subId `
    --location "swedencentral" `
    --template-file "main.bicep" `
    --parameters "param.bicepparam" `
    --no-prompt `
    --output table

add global admin

$User = az ad user show --id "adm.karol@abc.se" --query "id" --output tsv
$GlobalAdmin = '62e90394-69f5-4237-9190-012177145e10'

$Body="{'principalId':'$user', 'roleDefinitionId': '$GlobalAdmin', 'directoryScopeId': '/'}"  
az rest --method POST --uri https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments --headers "Content-Type=application/json" --body $Body

$RoleId = az rest --method GET --uri https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments --headers "Content-Type=application/json" --query "value[?principalId=='$user' && roleDefinitionId=='$GlobalAdmin'].id" --output tsv
if($null -ne $RoleId) {
    az rest --method DELETE --uri https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments/$RoleId --headers "Content-Type=application/json"
}

query

az --query "[].name" -o tsv
az --query "[?name=='sub-infra-dev-01']"
az --query "[?name=='sub-infra-dev-01'].id" -o tsv
az --query "[?isDefault]"
az --query "[?displayName=='$spiname'].id" --all -o tsv
az --query "[?name=='devops'].id" -o tsv
az --query [].appId -o tsv
az --query "graphGroups" -o tsv
az --query "graphGroups[?contains(principalName,'Infrastruktur')].{principalName: principalName}" -o tsv
az --query "[?contains(name,'-prod-') && name!='sub-platform-prod-01']"
az --query "graphGroups[].{displayName:displayName, descriptor:descriptor}" --output table
az --query "graphGroups[?contains(principalName,'XXX')].{principalName: principalName}" -o tsv
az --query "graphGroups[?displayName=='Project Collection Administrators'].descriptor" -o tsv
az --query "graphGroups[?principalName=='[orgxxx]\Project Collection Administrators'].descriptor" -o tsv
az --query "graphGroups[?contains(principalName,'Project Collection Administrators')].descriptor" -o tsv
az --query "[?contains(displayName, 'grp-rbac-sub-infra-prod-01-reader')]" --output tsv
az --query "[?properties.privateLinkServiceConnectionState.status=='Pending'].id"
az --query "[?displayName=='sub-infra-dev-01' && state=='Enabled'].id" -o tsv
az --query "[?definition.name=='ssg-labb' && result=='canceled' && contains(startTime, '$(Get-Date -Format "yyyy-MM-dd")')]"
az vm image list  --publisher MicrosoftWindowsServer --offer WindowsServer --location westeurope -o tsv --all --query "[?contains(sku, '2025')]"

About

Azure CLI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors