使用Azure CLI命令查找VM的最后日期

发布于 2025-01-24 14:39:25 字数 97 浏览 2 评论 0原文

我有一个带有不同资源组和不同虚拟机的Azure帐户。我想知道如何确定哪些未使用。例如,使用Azure CLI命令,检查用户启动或使用虚拟机的最后日期。

请帮助我...

I have an account with Azure with different Resource Group and different virtual machine. I would like to know how I can determine which ones are unused. For example check the last date where the virtual machine was started or used by the user using azure cli command.

Please help me out with this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆凄美了谁 2025-01-31 14:39:25

最简单的可能是看VM的功能。
首先列出所有VM,然后运行一个查询,您可以在其中滤除与特定资源组属于特定资源组的查询:

az vm list -d  --query '[?powerState == `VM deallocated` && resourceGroup==`resource_group`]'

有关查询的更多信息,请在Microsoft Docs页面上查找“ Jmespath-Query”。希望这会有所帮助。

Easiest would probably to look at the powerstate of a vm.
First list all the vm's and then run a query where you filter out those that are deallocated and belong to a specific resource group:

az vm list -d  --query '[?powerState == `VM deallocated` && resourceGroup==`resource_group`]'

For more information on the queries look up 'JMESPath-query' on the Microsoft docs page. Hopefully this helps.

一枫情书 2025-01-31 14:39:25

我想知道如何确定哪些未使用

目前未使用,因此无法使用CLI来做到这一点。

检查虚拟机启动或使用的最后日期

我们可以使用PowerShell获取此信息。随后。

  1. 使用使用 get -azvm -vmname xxxx -rgname xxx -status
# To retrieve the date of VM was Deallocated.
$vmDeallocatedDate = Get-AzVM -VMName <Your VM name> -ResourceGroupName <Your ResourceGroup Name> -Status
$vmDeallocatedDate.Statuses[0].Time
  1. 列出所有 vm和timestamp 触发了 dealLocation
Get-AzLog -Status Accepted -DetailedOutput | ?{$_.Authorization.Action -eq "Microsoft.Compute/virtualMachines/deallocate/action"} | fl ResourceId,EventTimestamp

参考

  1. get-azlog获取VM DealLocate状态
  2. get-azvm -Status获取VM DealLocate状态

I would like to know how I can determine which ones are unused

Currently, there is no way to do that using cli.

check the last date where the virtual machine was started or used

We can get this information using PowerShell. which follows.

  1. Get data information of deallocated VM using Get-AzVM -VMName xxxx - RgName xxx -Status
# To retrieve the date of VM was Deallocated.
$vmDeallocatedDate = Get-AzVM -VMName <Your VM name> -ResourceGroupName <Your ResourceGroup Name> -Status
$vmDeallocatedDate.Statuses[0].Time
  1. List all the VM's and the timestamp of the action that triggered the Deallocation
Get-AzLog -Status Accepted -DetailedOutput | ?{$_.Authorization.Action -eq "Microsoft.Compute/virtualMachines/deallocate/action"} | fl ResourceId,EventTimestamp

References

  1. Get-AzLog to get VM Deallocate status
  2. Get-AzVM -status to get VM Deallocate status
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文