Reputation: 43
I have been trying to get the VM OS name from Microsoft Azure using PowerShell.
I think I am very close to the solution but I don't know where I'm going wrong.
This is the command that I am using to get the VM details:
Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1 | Select OsType
The answer I get is just blank.
When running the following command:
Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1
I get all the details that belong to that VM.
Upvotes: 3
Views: 18386
Reputation: 1722
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}}
RESULT:
Upvotes: 1
Reputation: 1009
You can get resource groups' VMs by Get-AzureRmVM
and classic VMs by Get-AzureVM
. Both of the returning values of the two cmdlets contain OS type properties but in different paths.
Get-AzureRmVM
, the OS type property path is $vm.StorageProfile.OsDisk.OsType
Get-AzureVM
, the OS type property path is $vm.VM.OSVirtualHardDisk.OS
There exists a sample code about fetching Azure VM OS Type here: https://gallery.technet.microsoft.com/How-to-retrieve-Azure-5a3d3751
Upvotes: 1
Reputation: 26414
The osType
property lives inside $_.StorageProfile.osDisk
Get-AzureRmVM -ResourceGroupName TEST -Name VMNAME |
Format-Table Name, @{l='osType';e={$_.StorageProfile.osDisk.osType}}
Name osType
------ ------
VMNAME Windows
Use https://resources.azure.com to explore the object representation when in doubt, or pipe to Show-Object
, like i did below.
Upvotes: 9