Azure Windows VM

编程入门 行业动态 更新时间:2024-10-24 16:30:28
本文介绍了Azure Windows VM-如何确定它所在的资源组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Azure Windows VM上运行了C#代码.有没有办法让我找出此VM所在的资源组?

I have C# code running on an Azure Windows VM. Is there a way for me to find out what Resource Group this VM is in?

VM已使用Azure资源管理API部署(新的,不是经典的)

VM has been deployed with Azure Resource Management API (new, not classic)

推荐答案

以下内容将保证能够在不同资源组中区分具有相同名称的vm:

The following will guarantee the ability to distinguish between vm's with the same name across different resource groups:

从C#代码中找到vmId(涉及在以下链接中运行命令之一,或者可能使用Azure SDK: azure.microsoft/zh-cn/blog/accessing-and-using-azure-vm-unique-id/).如果使用Linux VM,请确保考虑到不同的字节序,否则vmId将不匹配.

From your C# code, find the vmId (involves running one of the commands at the following link or possibly using an Azure SDK: azure.microsoft/en-us/blog/accessing-and-using-azure-vm-unique-id/). If using a Linux VM, be sure to take into account the different endian-ness, otherwise the vmId will not match.

一旦有了vmId,就可以使用CLI或Powershell(或可能的Azure SDK)列出订阅中的所有VM,然后在列表中进行搜索以查找哪个VM具有从计算机中获得的vmId..然后,您应该能够从该json的json的"id"字段中解析出该资源组的名称(正如Gaurav所提到的,它是其中包含资源组的字符串).例如,请尝试以下操作:

Once you have the vmId, you can use either CLI or Powershell (or potentially an Azure SDK) to list all of the VM's in the subscription, then search through the list to find which VM has the vmId you got from the machine. Then you should be able to parse out the resource group name from the "id" field of the json for that VM (which, as Gaurav mentioned, is a string with the resource group in it). For an example, try the following:

azure vm list --json -vv

此命令将向您显示用于发出请求的URL和响应正文.在此正文中,您将找到"vmId"和"id"字段.例如,它发送的请求之一是:

This command will show you the url's it is using to make the requests and the response body. In this body you will find the "vmId" and "id" field. For instance, one of the requests it sends is:

management.azure/subscriptions/{my-subscription-id}/providers/Microsoft.Compute/virtualMachines?api-version=2015-06-15

,响应主体是带有相关条目的json.希望这可以帮助!:)

and the response body for this is the json with the relevant entries. Hope this helps! :)

更多推荐

Azure Windows VM

本文发布于:2023-11-12 12:43:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Azure   Windows   VM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!