How to retrieve vm by vmId, instead of resource id.

Songyeon Won 1 Reputation point
2021-02-18T09:02:19.537+00:00

I am developing a program that retrieve vm information using java sdk.

i can retrieve vm by resource id as below,

but i don't know, how to retrieve vm by vm id(uuid).

Thanks.

TokenCredential tokenCredential = new EnvironmentCredentialBuilder()
                    .authorityHost(AzureAuthorityHosts.AZURE_PUBLIC_CLOUD)
                    .build();

AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);

AzureResourceManager azureResourceManager = AzureResourceManager.configure()
                    .withLogLevel(HttpLogDetailLevel.BASIC)
                    .authenticate(tokenCredential, profile)
                    .withDefaultSubscription();

VirtualMachines virtualMachines = azureResourceManager.virtualMachines();

VirtualMachine vm = virtualMachines.getById("/subscriptions/*************/resourceGroups/*****/providers/Microsoft.Compute/virtualMachines/vm2");
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,372 questions
{count} votes