Azure - VM

1 - About

VM management in Azure

3 - Library

Most of the commands in this article are created with the cli but your can also used third party library.

Example with:

4 - Management

4.1 - Create

Everything you can specify on the web portal is available via a command-line flag or switch. +

Example with the azure cli:

az.cmd vm create ^
    --resource-group groupName ^
    --name vmName ^
    --image Oracle:Oracle-Linux:7.4:7.4.20170908 ^
    --size Standard_DS1_v2 ^
    --authentication-type password ^
    --admin-username userName ^
    --admin-password userPwd ^
    --location westeurope



{\ Finished ..
  "fqdns": "",
  "id": "/subscriptions/a3c34725-da6a-41ac-87fa-090f6b96d44d/resourceGroups/VGZ_OBIEE/providers/Microsoft.Compute/virtualMachines/HI-ORACLE-12-SE",
  "location": "westeurope",
  "macAddress": "00-0D-3A-26-99-A6",
  "powerState": "VM running",
  "privateIpAddress": "",
  "publicIpAddress": "",
  "resourceGroup": "groupName",
  "zones": ""

4.2 - Start / Stop

az.cmd vm start --name vmName --resource-group groupName
az.cmd vm stop --name vmName --resource-group groupName

4.3 - Reboot

logged in as root


Broadcast message from [email protected]
        (/dev/pts/0) at 2:04 ...

The system is going down for reboot NOW!

4.4 - Delete

az.cmd vm delete --name vmName --resource-group groupName

4.5 - Info

4.5.1 - Show

az.cmd vm show  --name vmName --resource-group groupName

4.5.2 - List

az.cmd vm list --output table

Name             ResourceGroup    Location
---------------  ---------------  ----------
ORACLE-12-SE  groupName        westeurope

# Without headers
az.cmd vm list --output table --query "[*].[name, resourceGroup]"
# With headers
az.cmd vm list --output table --query "[*].{VMName:name, OSType:storageProfile.osDisk.osType}"

4.6 - Nic

Get the Nic id

az.cmd vm show --resource-group myResourceGroup --name myVM -d --o tsv --query "networkProfile.networkInterfaces[].id"


4.7 - Get IP

  • Public

az vm show --resource-group myResourceGroup --name myVM -d --query [publicIps] --o tsv

4.8 - State

az vm show --resource-group myResourceGroup --name myVM -d --query [powerState] --o tsv

VM running
VM stopped

  • PowerState (don't forget the -d options)

az.cmd vm list --output table -d --query "[*].{Name:name, Group:resourceGroup, Power:powerState}"

4.9 - Run Command


az vm run-command invoke -g RG20ETL200-A -n su20etl201a --command-id RunShellScript --scripts "echo nico"

  "value": [
      "code": "ProvisioningState/succeeded",
      "displayStatus": "Provisioning succeeded",
      "level": "Info",
      "message": "Enable succeeded: \n[stdout]\nnico\n\n[stderr]\n",
      "time": null

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap