- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to retrieve the OS of the Azure VM using Azure CLI in PowerShell?
To retrieve the Azure VM OS using Azure CLI, we can use the “az vm” command but before that, need to make sure that you are connected to the Azure cloud and the subscription.
PS C:\> az vm show -n VMName -g VMRG --query "[storageProfile.imageReference.offer]" -otsv
OR
PS C:\> az vm show -n VMName -g VMRG --query storageProfile.imageReference.offer - otsv
Output
WindowsServer
To get the OS SKU or the operating system version, you can use,
PS C:\> az vm show -n VMName -g VMRG --query "[storageProfile.imageReference.sku]" -otsv
Output
2016-Datacenter
You can also use the below command to get the OS of the VM without providing the resource group name.
PS C:\> az vm list --query "[?name==VMName].{os:storageProfile.imageReference.offer}" -otsv
To get the OS version or SKU,
PS C:\> az vm list --query "[?name==VMName].{os:storageProfile.imageReference.sku}" -otsv
To combine all the outputs in the table format,
az vm list --query "[].{vmName:name, ResourceGroup:resourceGroup, os:storageProfile.imageReference.offer, version:storageProfile.imageReference.sku}" - otable
Advertisements