0

I am creating an ARM template for the Azure Log Analytics workspace.it has some queries which use azure VM's VMUUID.Is there is any way to fetch the azure VM's VMUUID in ARM template or any other ways to fetch azure VMUUID?

1 Answers1

0

According to a blog post from 2014 it should be possible to get the VMUUID for both Linux and Windows Hosts with some pretty straightforward scripts. Like this one (for windows):

$computerSystemProduct = Get-WmiObject -class Win32_ComputerSystemProduct -namespace root\CIMV2

'BIOS GUID:             "{0}"' -f $computerSystemProduct.UUID

These scripts could be run on the VMs themselves, or by using the "Run command" option offered from the VM's blade in Azure.

You can also deploy the script to run via the VM's ARM template, by using a VM extension. This way you can have the VMUUID ready right after the deployment completes. An example of how an extension could look in the template:

    {
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "apiVersion": "2020-12-01",
  "name": "[concat(parameters('vmName'),'/', 'GetVMUUID')]",
  "location": "[parameters('location')]",
  "dependsOn": [
      "[concat('Microsoft.Compute/virtualMachines/',parameters('vmName'))]"
  ],
  "properties": {
      "publisher": "Microsoft.Compute",
      "type": "CustomScriptExtension",
      "typeHandlerVersion": "1.7",
      "autoUpgradeMinorVersion":true,
      "settings": {
        "fileUris": [
          "https://raw.githubusercontent.com/<Path to the script for getting VMUUID>"
        ],
        "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File GetVMUUID.ps1"
      }
  }
}

Keep in mind that the script (the first codeblock) itself would need to be accessible for Azure Resource Manager through an URI. You could provide this either through a public GitHub repo (probably easiest) or through Azure Storage account and an SAS token.

Now, for getting the output out directly, I'm not so sure. One option is to append the script, and have it write to a file or location you can access later. Another option, which I haven't tried myself yet, is to get the output through the template itself as described in this sample: Azure Quickstart Template. I probably will spin an RG up for myself later to take a look, but feel free to tell me if you decide to check that route out, and how it went :)

This was longer than I expected to write, and might not be that clear, but I at least hope it can point you in the right direction!

Thanks, Emil