Azure VM创建日期

azure

4318 观看

6回复

112 作者的声誉

是否有任何Management API可以查找Azure VM创建日期?为云服务创建日期提供了托管服务属性API,但我们无法找到Azure VM创建日期。

作者: user2044374 的来源 发布者: 2013 年 4 月 6 日

回应 (6)


-1

9806 作者的声誉

没有办法通过我所知道的Windows Azure API来实现这一点。您是否尝试远程获取此值,或者将其用于实例?

如果您在实例上,您可能会尝试基于WMI获取它。这是在PowerShell中,但您可以适应C#,VB.NET或其他可以获取WMI信息的Scripting语言。

[reflection.Assembly]::LoadWithPartialName("system.management")
$wmiSearch = new-object -type System.Management.ManagementObjectSearcher -Arg "Select * from Win32_OperatingSystem"
$data = $wmiSearch.Get()
[System.Management.ManagementDateTimeConverter]::ToDateTime($data.InstallDate)

我在Azure VM上尝试了这个,它基本上就是为我创建了VM。您可能希望随着时间的推移测试此结果。此外,这只会让您获得虚拟机实际启动的时间。因此,如果您有一个运行良好的实例A,那么硬盘驱动器就会出现故障,并且Fabric Controller将实例移动到DC中的另一个位置并将其旋转回来,然后安装日期可能就是它的时间移动。这可能正是您正在寻找的,或者可能不是取决于您的要求。

作者: MikeWo 发布者: 06.04.2013 12:44

1

11 作者的声誉

我们可以在Blob存储中检索操作系统磁盘文件创建时间,这相当于虚拟机创建时间。查看更多https://social.msdn.microsoft.com/forums/azure/en-US/3da7750a-1a7d-4c62-b58a-a4b427b2520d/get-azure-vm-creationprovision-date

作者: Xiao Wang 发布者: 07.08.2015 09:17

2

674 作者的声誉

  1. 您可以在控制板上看到创建日期包含在磁盘名称中。 在此输入图像描述

  2. 您还可以使用Azure Powershell命令来检索:

    Get-AzureVM -ServiceName myubuntu1 | Get-AzureOSDisk | select MediaLink
    
作者: Steven 发布者: 21.01.2016 09:33

1

5446 作者的声誉

2016更新:仍然没有办法以可靠的方式快速获取VM创建日期(不,磁盘名称的日期部分不可靠)。

作者: jdc0589 发布者: 27.01.2016 07:44

1

41 作者的声誉

我最近为这类你可能觉得有用的东西写了一个函数。

该功能仅需要您的tenantID和具有正确权限的标识,并且将返回您关于Azure VM的创建日期,它们所在的资源组,OS和SKU的数据。

这是功能:

Function Get-AZVMCreated {
<#
.SYNOPSIS
Function "Get-AZVMCreated" will connect to a given tenant and parse through the subscriptions and output Azure VM details based on creation date.

.DESCRIPTION
Author: Pwd9000 (Pwd9000@hotmail.co.uk)
PSVersion: 5.1

The user must specify the TenantId when using this function.
The function will request access credentials and connect to the given Tenant.
Granted the identity used has the required access permisson the function will parse through all subscriptions 
and gather data on Azure Vms based on the creation date.

.EXAMPLE
Get-AZVMCreated -TenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

.PARAMETER TenantId
A valid Tenant Id object. e.g: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" <String>
#>

[CmdletBinding()]
param(
    [Parameter(Mandatory = $True,
        ValueFromPipeline = $True,
        HelpMessage = 'Please specify the tenant id? e.g: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"')]
    [string]$TenantId
)

#------------------------------------------------Obtain Credentials for Session------------------------------------------------------------
$Credential = Get-Credential

#---------------------------------------------Get all Subscription Ids for given Tenant----------------------------------------------------
$SubscriptionIds = (Get-AzureRmSubscription -TenantId $TenantId).Id

#-------------------------------------------------Create Empty Table to capture data-------------------------------------------------------
$Table = @()

Foreach ($Subscription in $SubscriptionIds) {
    Write-Host "Checking Subscription: $Subscription. for any Azure VMs and their creation date. This process may take a while. Please wait..." -ForegroundColor Green

    $RMAccount = Add-AzureRmAccount -Credential $Credential -TenantId $TenantId -Subscription $subscription
    Get-AzureRmDisk | Where-Object {$_.TimeCreated -le (Get-Date)} |
            Select-Object Name, ManagedBy, Resourcegroupname, TimeCreated |
            ForEach-Object {
                Try {
                    $ErrName = $_.Name
                    $AzDiskManagedBy = $_.managedby | Split-path -leaf
                    $AzDiskManagedByRG = $_.ResourceGroupName
                    $CreationDate = $_.TimeCreated
                    $OS = (Get-AzurermVM -name $AzDiskManagedBy -ResourceGroup $AzDiskManagedByRG).StorageProfile.ImageReference.Offer
                    $SKU = (Get-AzurermVM -name $AzDiskManagedBy -ResourceGroup $AzDiskManagedByRG).StorageProfile.ImageReference.SKU
                    $Table += [pscustomobject]@{VMName = $AzDiskManagedBy; Created = $CreationDate; ResourceGroup = $AzDiskManagedByRG; OperatingSystem = $OS; SKU = $SKU}
                }
                Catch {
                    Write-Host "Cannot determine machine name associated with disk: [$ErrName]. Skipping drive-check for this item..." -ForegroundColor Yellow
                    Write-Host "Continue Checking Subscription: $Subscription. for any Azure VMs and their creation date. This process may take a while. Please wait..." -ForegroundColor Green
                }
            }
}
$UniqueVMs = $Table | Sort -Unique -Property VMName
$UniqueVMs
Write-Host "" -ForegroundColor Green
Write-Host "Number of disks associated with VMs: $($Table.Count)" -ForegroundColor Green
Write-Host "Number of disks unable to associate with VMs: $($ErrName.Count)" -ForegroundColor Yellow
Write-Host "Number of unique Azure VMs associated with disks: $($UniqueVMs.Count)" -ForegroundColor Green
Write-Host "Script finished.." -ForegroundColor Green
}

然后,您可以调用并使用此类函数,例如:

$TenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$AZVMsAll = Get-AZVMCreated -TenantId $TenantId | sort-object -property Created
$Win10 = $AZVMsAll | Where-Object {$_.SKU -like "*Windows-10*"} | sort-object -property Created
$Win8 = $AZVMsAll | Where-Object {$_.SKU -like "*Win81*"} | sort-object -property Created
$Win7 = $AZVMsAll | Where-Object {$_.SKU -like "*Win7*"} | sort-object -property Created
$Server2008R2 = $AZVMsAll | Where-Object {$_.SKU -like "*2008-R2*"} | sort-object -property Created
$Server2012R2 = $AZVMsAll | Where-Object {$_.SKU -like "*2012-R2*"} | sort-object -property Created
$Server2016 = $AZVMsAll | Where-Object {$_.SKU -like "*2016*"} | sort-object -property Created
$RHEL = $AZVMsAll | Where-Object {$_.OperatingSystem -like "*RHEL*"} | sort-object -property Created
$Ubuntu = $AZVMsAll | Where-Object {$_.OperatingSystem -like "*Ubuntu*"} | sort-object -property Created
$Centos = $AZVMsAll | Where-Object {$_.OperatingSystem -like "*Centos*"} | sort-object -property Created

$AZVMsAll

在上面的例子中,您还可以使用定义的变量调用其他版本的OS,例如,对于所有Win7机器,您可以调用变量$ Win7等等...

作者: Pwd9000 发布者: 13.11.2018 08:17

0

1 作者的声誉

使用以下az命令获取磁盘创建日期...从此OS磁盘创建中,我们可以找到VM提供日期:

diskquery='[*].{Resourceid:id, name:name, timeCreated:timeCreated}'
az disk list --query "$diskquery"
作者: Gopi 发布者: 13.02.2019 05:19
32x32