How to get the Azure scale set name from the VM name on the computer

2.1k views Asked by At

I'm trying to grab the name of the Azure VM scale set from the computer's name. I'm able to get close, but not reliably so. I've found this article which mentions the (vmss name)(base 36 instance id) format which I found to be fairly accurate, although with VMSS names under 9 characters, I seem to get random extra characters added to my computer name which don't show up in Azure.

Ex: (in Azure Portal)

VMSS name = "win10"

Instance ID = 2

Computer name = "win10_2"

Therefore, I'd expect the machine name to be "win10000002", however, whenever I remote into the VM and look at the computer name, it shows "win10bc5n000002", note the extra "bc5n" added into it. Does anyone know why this happens or a way to reliably predict it so I can programmatically remove it when I grab the computer name on the machine? The length of my VMSS names won't be consistent, so I can't reliably split the string to remove the 4 extra chars.

EDIT: here's some screen shots of the Portal vs Computer name: enter image description here enter image description here

1

There are 1 answers

4
Charles Xu On BEST ANSWER

As you say that there is an unexcepted string "bc5n" in your Windows 10 VM name. But as I test that the computer name just consists of the scale set virtual machine name and a six-length number with the instance ID. The screenshot of the result which I test in the Azure portal here:

enter image description here enter image description here

And I think the random extra characters could be added yourself which you forget.

Update

The result is exactly as you say if the computer name is less than 9 characters. But it's the default setting if you do not change.

You can check in your existing Scale Set template on Azure Portal.

enter image description here

If you want to create an Azure Scale Set with an exact computer name, you can achieve that through the template. And set the property "computerNamePrefix" just with the name you input.

I have tested and the result below:

enter image description here