获取 Azure VM 创建日期
Get Azure VM creation date
是否有可能获取 VM 创建日期的方法?
我现在已经尝试了以下方法
AzureActivity
| where TimeGenerated > ago(90d)
| where ResourceProvider == "Microsoft.Compute" and OperationName == "Create or Update Virtual Machine"
| project Resource ,Datum = format_datetime(EventSubmissionTimestamp, 'MM') ,Caller
| distinct Datum , Resource , Caller
| order by Datum
此 kusto 查询将从与其连接的 VM 读取日志。并从虚拟机及其调用方 ID 获取所有创建或更新虚拟机操作。
但这是创建和 更新 所以每次更新 VM 时它都会给我双倍的值。
我也在 PowerShell 中尝试过
$GetVM = Get-AzureRMVM
Foreach ($vms in $GetVM)
{
$vm = get-azurermvm -name $vms.Name -ResourceGroupName $vms.ResourceGroupName
$log = Get-AzureRmLog -ResourceId $vm.Id -StartTime (Get-Date).AddDays(-90) -WarningAction silentlyContinue
Write-Output "- Found VM creation at $($log.EventTimestamp) for VM $($log.Id.split("/")[8]) in Resource Group $($log.ResourceGroupName) found in Azure logs"
}
但似乎也无法在日志文件中找到创建日期。有没有人知道是否可以在脚本语言、Kusto、Powershell 中找到虚拟机的创建日期,...
该门户确实在云服务的仪表板中显示为云服务创建,但未针对特定 VM 显示(您可以通过 Get-AzureService <cloud service name> | select DateCreated
使用 Azure PowerShell 查看)。
当您快速创建 VM 时,总会创建一个新的云服务,因此 VM 和云服务的创建时间相同。但由于您可以将多个 VM 添加到云服务,因此您不能总是依赖它。
在门户的 VM 仪表板上,如果您查看 VHD 列,在底部,VHD 名称包括磁盘创建日期作为名称的一部分,尽管这仅适用于从图片。如果 VM 是从磁盘创建的,则名称可以是任何名称。您可以使用 Get-AzureVM <cloud service name> <VM name> | Get-AzureOSDisk | select medialink
.
在 Azure PowerShell 中获取 OS 磁盘名称
门户管理服务下的操作日志让您可以搜索最近 30 天的操作,因此如果 VM 是在上个月创建的,您可以在那里找到操作的证据(例如 CreateHostedService
和 CreateDeployment
操作)。
对于从映像创建的 Windows 个 VM,WaSetup.log
上的时间戳和 C:\Windows\panther\
中的 WaSetup.xml
上的时间戳反映了供应 VM 的时间。
希望对您有所帮助。
如果创建日期晚于 90 天,则无法直接找出创建日期。但这里有一个很好的解决方法:https://savilltech.com/2018/02/13/checking-the-creation-time-of-an-azure-iaas-vm/
如果您检查相应资源组中的部署,您将看到该 RG 中每个部署的上次修改日期。
我获取 Azure VM 创建日期的最简单方法是 查看 OS 磁盘[的创建日期=26=]
- 浏览到 Azure 门户上的 VM
- 在左侧,单击边栏“磁盘”
- 在 OS 磁盘部分下,单击您的 OS 磁盘。
- 在 OS 磁盘的概览边栏选项卡中,您可以看到 创建时间字段。
注意:我所有的 Azure VM 都是使用 OS 磁盘创建的,并且从未更改过。
希望对您有所帮助。干杯。
我通过调整 ActivityLog 查询而不是 Powershell 找到了另一种让它为我工作的方法。使用 HTTPRequest 属性 似乎可以满足我的需求。
AzureActivity
| where TimeGenerated > ago(7d)
| where ResourceProvider contains "Microsoft.Compute" and OperationName == "Create or Update Virtual Machine"
| where HTTPRequest contains "PUT"
| project VMName = Resource, Created_On = format_datetime(EventSubmissionTimestamp,'dd-MM-yyyy-HHtt'), User = Caller
| distinct Created_On, VMName, User
| order by Created_On
就我而言,我试图删除过去 7 天内的虚拟机。由于某些原因,下面的查询时间显示不正确,因此我不得不将其转换为我的时区。
AzureActivity
| where TimeGenerated > ago(7d)
| where ResourceProvider == "Microsoft.Compute" and OperationName == "Delete Virtual Machine"
| where HTTPRequest contains "DELETE"
| extend MyTimeZone = EventSubmissionTimestamp + 8h
| project VM_Name = Resource, Deleted_On = format_datetime(MyTimeZone, 'dd-MM-yyyy-HHtt'), User = Caller
| distinct Deleted_On , VM_Name , User
| order by Deleted_On
是否有可能获取 VM 创建日期的方法?
我现在已经尝试了以下方法
AzureActivity
| where TimeGenerated > ago(90d)
| where ResourceProvider == "Microsoft.Compute" and OperationName == "Create or Update Virtual Machine"
| project Resource ,Datum = format_datetime(EventSubmissionTimestamp, 'MM') ,Caller
| distinct Datum , Resource , Caller
| order by Datum
此 kusto 查询将从与其连接的 VM 读取日志。并从虚拟机及其调用方 ID 获取所有创建或更新虚拟机操作。
但这是创建和 更新 所以每次更新 VM 时它都会给我双倍的值。
我也在 PowerShell 中尝试过
$GetVM = Get-AzureRMVM
Foreach ($vms in $GetVM)
{
$vm = get-azurermvm -name $vms.Name -ResourceGroupName $vms.ResourceGroupName
$log = Get-AzureRmLog -ResourceId $vm.Id -StartTime (Get-Date).AddDays(-90) -WarningAction silentlyContinue
Write-Output "- Found VM creation at $($log.EventTimestamp) for VM $($log.Id.split("/")[8]) in Resource Group $($log.ResourceGroupName) found in Azure logs"
}
但似乎也无法在日志文件中找到创建日期。有没有人知道是否可以在脚本语言、Kusto、Powershell 中找到虚拟机的创建日期,...
该门户确实在云服务的仪表板中显示为云服务创建,但未针对特定 VM 显示(您可以通过 Get-AzureService <cloud service name> | select DateCreated
使用 Azure PowerShell 查看)。
当您快速创建 VM 时,总会创建一个新的云服务,因此 VM 和云服务的创建时间相同。但由于您可以将多个 VM 添加到云服务,因此您不能总是依赖它。
在门户的 VM 仪表板上,如果您查看 VHD 列,在底部,VHD 名称包括磁盘创建日期作为名称的一部分,尽管这仅适用于从图片。如果 VM 是从磁盘创建的,则名称可以是任何名称。您可以使用 Get-AzureVM <cloud service name> <VM name> | Get-AzureOSDisk | select medialink
.
门户管理服务下的操作日志让您可以搜索最近 30 天的操作,因此如果 VM 是在上个月创建的,您可以在那里找到操作的证据(例如 CreateHostedService
和 CreateDeployment
操作)。
对于从映像创建的 Windows 个 VM,WaSetup.log
上的时间戳和 C:\Windows\panther\
中的 WaSetup.xml
上的时间戳反映了供应 VM 的时间。
希望对您有所帮助。
如果创建日期晚于 90 天,则无法直接找出创建日期。但这里有一个很好的解决方法:https://savilltech.com/2018/02/13/checking-the-creation-time-of-an-azure-iaas-vm/
如果您检查相应资源组中的部署,您将看到该 RG 中每个部署的上次修改日期。
我获取 Azure VM 创建日期的最简单方法是 查看 OS 磁盘[的创建日期=26=]
- 浏览到 Azure 门户上的 VM
- 在左侧,单击边栏“磁盘”
- 在 OS 磁盘部分下,单击您的 OS 磁盘。
- 在 OS 磁盘的概览边栏选项卡中,您可以看到 创建时间字段。
注意:我所有的 Azure VM 都是使用 OS 磁盘创建的,并且从未更改过。
希望对您有所帮助。干杯。
我通过调整 ActivityLog 查询而不是 Powershell 找到了另一种让它为我工作的方法。使用 HTTPRequest 属性 似乎可以满足我的需求。
AzureActivity
| where TimeGenerated > ago(7d)
| where ResourceProvider contains "Microsoft.Compute" and OperationName == "Create or Update Virtual Machine"
| where HTTPRequest contains "PUT"
| project VMName = Resource, Created_On = format_datetime(EventSubmissionTimestamp,'dd-MM-yyyy-HHtt'), User = Caller
| distinct Created_On, VMName, User
| order by Created_On
就我而言,我试图删除过去 7 天内的虚拟机。由于某些原因,下面的查询时间显示不正确,因此我不得不将其转换为我的时区。
AzureActivity
| where TimeGenerated > ago(7d)
| where ResourceProvider == "Microsoft.Compute" and OperationName == "Delete Virtual Machine"
| where HTTPRequest contains "DELETE"
| extend MyTimeZone = EventSubmissionTimestamp + 8h
| project VM_Name = Resource, Deleted_On = format_datetime(MyTimeZone, 'dd-MM-yyyy-HHtt'), User = Caller
| distinct Deleted_On , VM_Name , User
| order by Deleted_On