使用PowerShell获取Azure VM OS名称

时间:2017-01-03 14:35:25

标签: powershell azure

我一直在尝试使用PowerShell从Microsoft Azure获取VM OS名称。

我认为我非常接近解决方案,但我不知道自己哪里出错了。

这是我用来获取VM详细信息的命令:

Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1 | Select OsType

我得到的答案只是空白。

运行以下命令时:

Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1

我获得了属于该VM的所有细节。

3 个答案:

答案 0 :(得分:7)

osType属性位于$_.StorageProfile.osDisk

Get-AzureRmVM -ResourceGroupName TEST -Name VMNAME |
    Format-Table Name, @{l='osType';e={$_.StorageProfile.osDisk.osType}}

Name      osType
------    ------
VMNAME    Windows

使用https://resources.azure.com在有疑问的情况下探索对象表示,或者管道到Show-Object,就像我在下面所做的那样。

Show-Object

答案 1 :(得分:1)

您可以获得资源组' Get-AzureRmVM的虚拟机和Get-AzureVM的经典虚拟机。两个cmdlet的返回值都包含OS类型属性,但位于不同的路径中。

  • 对于cmdlet Get-AzureRmVM,操作系统类型属性路径为$vm.StorageProfile.OsDisk.OsType
  • 对于cmdlet Get-AzureVM,操作系统类型属性路径为$vm.VM.OSVirtualHardDisk.OS

此处存在有关获取Azure VM操作系统类型的示例代码:https://gallery.technet.microsoft.com/How-to-retrieve-Azure-5a3d3751

答案 2 :(得分:0)

Get-AzVM -name SERVERNAME | select name, @{n="OS";E={$_.StorageProfile.OsDisk.OsType}}, @{n="Offer";E={$_.StorageProfile.ImageReference.offer}} , @{n="SKU";E={$_.StorageProfile.ImageReference.sku}}, @{n="Publisher";E={$_.StorageProfile.ImageReference.Publisher}} 

结果:

enter image description here