question

VikasNeekhra-5125 avatar image
0 Votes"
VikasNeekhra-5125 asked shivapatpi-MSFT answered

How to create dynamic url of a Azure Virtual Machine

I need to create a dynamic Azure virtual machine url in Azure programmatically... I have this info (Subscription, resource group and resource name) of a VM and using that I need to create a url of that specific VM in Azure portal, so that once a user clicks on that link will redirect the user to that VM page in Azure cloud console.

What I have seen in the below url is active directory which I don't have for that specific customer/subscription, so how I can find that programmatically, or is there any other way I can create the direct url of a Azure VM. Please suggest

https://portal.azure.com/#@<active directory>.onmicrosoft.com/resource/subscriptions/xxxxxxxxxx-yyyyyyy-zzzzzzzzzzzzzzzz/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines/<resource-name>/overview

azure-virtual-machines
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered

Hello @VikasNeekhra-5125 ,
In general the URL on top of the Azure Portal it shows only after the user is authenticated under that subscription Tenant i.e. user should have subscription access.
There is a Azure CLI command to get the active directory name of the logged-in subscription.

When you do : az ad signed-in-user show
It will display all the information, look out for the attribute "userPrincipalName"
Or you can say: az ad signed-in-user show --query 'userPrincipalName'

You can use the output of the previous command and add it to build that complete URL for accessing the Virtual Machine.

Regards,
Shiva.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.