如何检索已删除的Azure VM的vmid

juud5qan  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(114)

是否有API或powershell命令可用于检索Azure中已删除虚拟机的vmid。我需要检索此值来更新我们的内部CMDB系统。到目前为止,尝试使用更改分析休息API没有运气,因为ARM模板也被删除,VM删除API调用没有返回任何值。我可以在资源组活动日志的已更改属性中看到vmid,只是想知道是否有方法通过编程检索此值。请让任何人知道以前尝试过这个,任何帮助将不胜感激。
谢谢

zaqlnxep

zaqlnxep1#

要检索已删除Azure VM的vmid,请使用以下PowerShell命令:

Get-AzActivityLog -ResourceId "/subscriptions/209654eb-1867-49df-9395XXXXX/resourcegroups/RgName/providers/microsoft.compute/virtualmachines/Vmname"

输出

HttpRequest          : 
                       ClientId        : 5c4691fc-a586-466a-80d7-XXXXX
                       Method          : PUT
                       Url             : https://management.azure.com/subscriptions/209654eb-1867-49df-9395-7fXXXXX/resourcegroups/imran/providers/Micros
                       oft.Compute/virtualMachines/vm333?api-version=2022-03-01
                       ClientIpAddress : 49.207.231.16
Properties           : 
                       statusCode     : Created
                       serviceRequestId: 
                       responseBody   : {"name":"vm333","id":"/subscriptions/209654eb-1867-49df-9395-7fXXXXX/resourceGroups/imran/providers/Microsoft.Com
                       pute/virtualMachines/vm333","type":"Microsoft.Compute/virtualMachines","location":"eastus","properties":{"vmId":"109bfd81-569c-425f-bc7
                       7-83de341fddae","hardwareProfile":{"vmSize":"Standard_B1s"},"storageProfile":{"imageReference":{"publisher":"MicrosoftWindowsServer","o
                       ffer":"WindowsServer","sku":"2022-datacenter-azure-edition","version":"latest","exactVersion":"20348.1787.230607"},"osDisk":{"osType":"
                       Windows","createOption":"FromImage","caching":"ReadWrite","managedDisk":{"storageAccountType":"StandardSSD_LRS"},"deleteOption":"Delete
                       ","diskSizeGB":127},"dataDisks":[],"diskControllerType":"SCSI"},"osProfile":{"computerName":"vm333","adminUsername":"imran123","windows
                       Configuration":{"provisionVMAgent":true,"enableAutomaticUpdates":true,"patchSettings":{"patchMode":"AutomaticByOS","assessmentMode":"Im
                       ageDefault","enableHotpatching":false},"enableVMAgentPlatformUpdates":false},"secrets":[],"allowExtensionOperations":true,"requireGuest
                       ProvisionSignal":true},"securityProfile":{"uefiSettings":{"secureBootEnabled":true,"vTpmEnabled":true},"securityType":"TrustedLaunch"},
                       "networkProfile":{"networkInterfaces":[{"id":"/subscriptions/209654eb-1867-49df-9395-7f0905ec6833/resourceGroups/imran/providers/Micros
                       oft.Network/networkInterfaces/vm333470","properties":{"deleteOption":"Detach"}}]},"diagnosticsProfile":{"bootDiagnostics":{"enabled":tr
                       ue}},"licenseType":"Windows_Server","provisioningState":"Creating","timeCreated":"2023-06-19T06:57:40.4398142+00:00"}}
                       eventCategory  : Administrative
                       entity         : 
                       /subscriptions/209654eb-1867-49df-9395-7f0905ec6833/resourcegroups/imran/providers/Microsoft.Compute/virtualMachines/vm333
                       message        : Microsoft.Compute/virtualMachines/write
                       hierarchy      : 2773f7fd-d343-4afXXXXXX/VenkatGroup/209654eb-1867-49df-93XXXXX
Level                : Informational
SubmissionTimestamp  : 19-06-2023 06:58:46
EventTimestamp       : 19-06-2023 06:57:42
EventName            : End request
Category             : Administrative
ResourceProviderName : Microsoft.Compute
OperationName        : Create or Update Virtual Machine
Status               : Accepted
SubStatus            : Created (HTTP Status Code: 201)
Caller               : mtuser1@m365x56209219.onmicrosoft.com
Description          : 
Id                   : /subscriptions/209654eb-1867-49df-9395-7f0905ec6833/resourcegroups/imran/providers/Microsoft.Compute/virtualMachines/vm333/events/2a108
                       5f1-c590-4479-a547-e6c53d0acf64/ticks/638227546629109956
EventDataId          : 2a1085f1-c590-4479-a547-e6c53d0acf64
CorrelationId        : 9021d8d7-4ad1-4ca6-893d-1XXXXX
ResourceGroupName    : imran
ResourceId           : /subscriptions/209654eb-1867-49XXXXX7f0905ec6833/resourcegroups/imran/providers/Microsoft.Compute/virtualMachines/vm333
ResourceType         : 
OperationId          : 4ff37a22-dc55-4016-be4a-8XXXXX
SubscriptionId       : 209654eb-186XXXX7f0905ec6833
TenantId             :
  • 您可以在下面的HTTP请求属性中找到已删除vm的vmid,如下所示:*

相关问题