Getting Azure VM OS name using PowerShell
Solution 1
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.
Solution 2
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:
Solution 3
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.
- For the cmdlet
Get-AzureRmVM
, the OS type property path is$vm.StorageProfile.OsDisk.OsType
- For the cmdlet
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
user2956653
Updated on June 04, 2022Comments
-
user2956653 almost 2 years
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.
-
evilSnobu over 7 yearsNon-programming related questions are best suited for serverfault.com
-
Jason Ye over 7 years@user2956653 you can use (get-azurermvm -ResourceGroupName jason -Name vm1).StorageProfile.OsDisk.OsType to get the type.
-
-
user2956653 over 7 yearsThank you for the answer! it worked like a treat. and the website seems very useful thank you.