是否有 Azure powershell cmdlet 来获取订阅中 ARM VM 的核心 cpu
Is there an Azure powershell cmdlet to get cores, cpu of an ARM VM in a subscription
我正在尝试使用 Get-AzureRmVM 获取订阅中的 ARM VM 列表,并使用 HardwareProfile.VmSize 对象获取它们的实例大小。有没有办法使用 cmdlet 为每个虚拟机获取 #of Cpu、#of Cores 等(就像在经典中使用 Get-AzureRoleSize cmdlet)?
你是说使用命令来获取这样的信息吗?
PS C:\User> $size = (Get-AzureRmVM -ResourceGroupName ubuntu -Name vm1).HardwareProfile.VmSize
PS C:\Users> get-azurermvmsize -location eastus | ?{ $_.name -eq $size }
Name NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB
---- ------------- ---------- ---------------- -------------- --------------------
Standard_DS1_v2 1 3584 2 1047552 7168
如果你想获得多个虚拟机的总核心数,这里是完整的解决方案:
# Calculating total Amount of Cores
Write-Output "Calculating the total Cores of VMs ..."
try {
$TotalCores = $null
$Location = "westeurope"
$Cores = $null
$TotalVMs = (Get-AzVM -Status | Where-Object { $_.ProvisioningState -eq "Succeeded" }) | Sort-Object -Property Name
foreach ($VM in $TotalVMs) {
Write-Output "Checking $($Vm.Name) ..."
$VMSize = (Get-AzVM -Name $VM.Name).HardwareProfile.VmSize
$Cores = (Get-AzVMSize -location $Location | Where-Object { $_.name -eq $VMSize }).NumberOfCores
$TotalCores += $Cores
}
Write-Output "Wow! Found '$TotalCores' Cores ..."
}
catch {
$ErrorMsg = "[ERROR] while calculating the total CPU Cores: $($_.Exception.Message)!"
Write-Error -Message $ErrorMsg
}
我正在尝试使用 Get-AzureRmVM 获取订阅中的 ARM VM 列表,并使用 HardwareProfile.VmSize 对象获取它们的实例大小。有没有办法使用 cmdlet 为每个虚拟机获取 #of Cpu、#of Cores 等(就像在经典中使用 Get-AzureRoleSize cmdlet)?
你是说使用命令来获取这样的信息吗?
PS C:\User> $size = (Get-AzureRmVM -ResourceGroupName ubuntu -Name vm1).HardwareProfile.VmSize
PS C:\Users> get-azurermvmsize -location eastus | ?{ $_.name -eq $size }
Name NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB
---- ------------- ---------- ---------------- -------------- --------------------
Standard_DS1_v2 1 3584 2 1047552 7168
如果你想获得多个虚拟机的总核心数,这里是完整的解决方案:
# Calculating total Amount of Cores
Write-Output "Calculating the total Cores of VMs ..."
try {
$TotalCores = $null
$Location = "westeurope"
$Cores = $null
$TotalVMs = (Get-AzVM -Status | Where-Object { $_.ProvisioningState -eq "Succeeded" }) | Sort-Object -Property Name
foreach ($VM in $TotalVMs) {
Write-Output "Checking $($Vm.Name) ..."
$VMSize = (Get-AzVM -Name $VM.Name).HardwareProfile.VmSize
$Cores = (Get-AzVMSize -location $Location | Where-Object { $_.name -eq $VMSize }).NumberOfCores
$TotalCores += $Cores
}
Write-Output "Wow! Found '$TotalCores' Cores ..."
}
catch {
$ErrorMsg = "[ERROR] while calculating the total CPU Cores: $($_.Exception.Message)!"
Write-Error -Message $ErrorMsg
}