
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieve Operating System of Azure VM Using PowerShell
To retrieve the OS details of the Azure VM, we need to use the Get-AzVM command.
Example
Get-AzVM -VMName TestMachine2k16
When you run the above command, it retrieves the VM TestMachine2k16 information and there is an OSType property which shows that if the VM’s OS is Linux or Windows, or any other type.
But when you select the OSType, you won’t get anything. See below.
Example
PS C:\> Get-AzVM -VMName TestMachine2k16 | Select OStype OStype ------
Because this property is a part of another property and hence can’t be accessed directly. When you expose the full properties of the VM, you will get the StorageProfile, which contains the OS information.
Example
PS C:\> $vm = Get-AzVM -VMName TestMachine2k16 PS C:\> $vm | fl *
Output
Use the below command,
Example
PS C:\> $vm.StorageProfile.ImageReference Publisher : MicrosoftWindowsServer Offer : WindowsServer Sku : 2016-Datacenter Version : latest ExactVersion : 14393.4225.2102030345 Id :
So here we got both the Server Edition and the version.
Output
PS C:\> $osver = $vm.StorageProfile.ImageReference.Offer + " $($vm.StorageProfile.ImageReference.Sku)" PS C:\> $osver WindowsServer 2016-Datacenter
Advertisements