AZ Cheat Sheet
Login and Subscription
az login --use-device-code
az account show
- Set Subscription
az account set --subscription SubscriptionName
Storage-Account
- List Storage Account
az storage account list --query [*].name --output tsv az storage account list --query [*].primaryLocation --output tsv az storage account list --query [*].resourceGroup --query [*].name
- Create Storage Account
az storage account create --location eastus --name ContainerName --resource-group RG --sku Standard_RAGRS --kind BlobStorage --access-tier Hot
- Delete Storage-Account
az storage account delete --name Storage-Account-Name -y az storage account delete --name Storage-Account-Name --resource-group RG az storage account delete --name Storage-Account-Name --resource-group RG -y
- Get Keys
az storage account keys list --account-name ContainerName --output table az storage account keys list --resource-group RG --account-name ContainerName --output table
- Create Container
az storage container create --name Container-Name --account-name Storage-Account-Name --account-key xyz...==
- List Container
az storage container list --account-name Storage-Account-Name --account-key xyz...== --output table
- Delete Container
az storage container delete --account-name Storage-Account-Name --account-key xyz...== --output table
- Copy Data from local to Container
az storage blob upload-batch --destination Container-Name --pattern "*.exe" --source "c:\Users\admin\Downloads" --account-name Storage-Account-Name --account-key xyz...==
- Copy data between two container within the same Storage-Account
az storage blob copy start-batch --destination-container Container-Name --account-name Storage-Account-Name --account-key xyz...== --source-account-name Storage-Account-Name --source-account-key xyz...== --source-container Container-Name
- Copy data between two storage accounts
az storage blob copy start-batch --destination-container Container-Name --account-name Storage-Account-Name --account-key xyz...== --source-account-name Storage-Account-Name --source-account-key xyz...== --source-container ContainerName
- List Blob data (BASH)
az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz...==
- List Blob data (BASH), Filenames only
az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz...== --query [*].name --output tsv
- List Blob data and put it into an Array (BASH), watch the query and output
BLOBS=$(az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz...== --query [*].name --output tsv)
- List Array data
for BLOB in $BLOBS do echo "$BLOB" done
- List Array data and download to /mnt/d/test/
for BLOB in $BLOBS do echo "Download: $BLOB" az storage blob download -n $BLOB -f /mnt/d/test/$BLOB -c ContainerName --account-name StorageAccountName --account-key xyz...== done
- Delete BLOB
az storage blob delete-batch --source ContainerName --pattern '*.gz' --account-name Storage-Account-Name --account-key xyz...==
SAS Keys
- Create SAS Token on BLOB
az storage blob generate-sas \ --account-name Storage-Account-Name \ --account-key xyz...== \ --container-name Container-Name \ --name file-Name \ --permissions acdrw \ --expiry 2021-01-18
- Test
https://<StorageAccount-Name>.blob.core.windows.net/<Container-Name>/<FileName>?xyz...==
- Create SAS Token on Container
Important: You need to add yourself to the role Storage Blob Data Contributor, it will NOT WORK if you skip this step, for mor informattion see: https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-rbac-portal
az storage container generate-sas --account-name Storage-Account-Name --name Container-Name --permissions acdlrw --expiry 2021-01-20 --auth-mode login --as-user
- Note that the key MUST contain ske and sig , otherwise the key is INVALID, Valid return looks like:
"se=2021-01-20&sp=racwdl&sv=2018-11-09&sr=c&skoid=139be1d7-4d53-4d8a-90e2-cc7ace745ad1&sktid=71d4c841-93b3-47b4-ab47-88c7d11f56d2&skt=2021-01-16T19%3A37%3A54Z&ske=2021-01-20T00%3A00%3A00Z&sks=b&skv=2018-11-09&sig=LMhhiOrZoEQPxgaemkKOZ2eY8W6Ee4ZE5zEWZu2y4Js%3D"
Not Specified
az vm show --resource-group "DBTRG" --name "vm-ubuntu01" --query "storageProfile.osDisk.managedDisk.id" | grep -oP 'disks/\K.+' | rev | cut -c2- | rev