0

I do only have access on a Windows VM which is hosted on Azure.

Is there a way to find out the VM size inside of the virtual machine, lets say for example over commandline (powershell / cmd), without having further information about the envrionment like for example Ressource Group or VM Ressource Name?

I did find a way like this, but it requires the information about the name of VM and Ressource group:

$VM = Get-AzureRMVM –Name HSG-Linux1 –ResourceGroupName HSG-AzureRG
$VM.HardwareProfile

Source

1 Answer 1

3

You can use the metada to get the VM information inside the VM like this:

Invoke-RestMethod -Headers @{"Metadata"="true"} -URI http://169.254.169.254/metadata/instance/compute?api-version=2019-03-11 -Method get

For more details, see Azure Instance Metadata service. You can also put the output as a variable, then get the special properties. For example:

$vm = Invoke-RestMethod -Headers @{"Metadata"="true"} -URI http://169.254.169.254/metadata/instance/compute?api-version=2019-03-11 -Method get
$vm.vmSize

Or get the property directly through the request like this:

$vmSize = Invoke-RestMethod -Headers @{"Metadata"="true"} -URI "http://169.254.169.254/metadata/instance/compute/vmSize?api-version=2019-03-11&&format=text" -Method get
6
  • Great, I was searching for this command for hours. Thanks a million Charles Xu. By the way, $vm.compute.resourceGroupName didn't work for me, but for that $vm.vmSize works great.
    – Baku Bakar
    Sep 17, 2019 at 9:15
  • @EmbaBakar It's just an example as I said. You can get the info as you want. Then if it works for you, you can accept it as the answer.
    – Charles Xu
    Sep 17, 2019 at 9:17
  • Cool, you did change your answer to $vm.vmSize which is a working well example. Now I can accept the answer. Good cooperation.
    – Baku Bakar
    Sep 17, 2019 at 9:29
  • @EmbaBakar What is the reason that you unmark the answer?
    – Charles Xu
    Sep 17, 2019 at 9:41
  • Why did you edit your correct example again to a not working example? Is the following command working on your env: $vm.compute.vmSize ? In my env. it doesn't give an output, the correct way to get an output is $vm.vmSize.
    – Baku Bakar
    Sep 17, 2019 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.