![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 Export the azure VM tags using PowerShell?
There are two ways to get the applied azure VM tags using PowerShell.
- Using Tags Property of the Azure VM
- Using the Get-AZTag command.
Example
PS C:\> Get-AzVM -VMName Testmachine2k12 | Select -ExpandProperty Tags Key Value --- ----- Patching_Day Sunday Owner Chirag
Another way is by using the Get-AZTag command.
PS C:\> $vm = Get-AzVM -VMName TestMachine2k12 PS C:\> Get-AzTag -ResourceId $vm.Id | Select -ExpandProperty Properties
Output
TagsProperty ------------ {[Owner, Chirag], [Patching_Day, Sunday]}
We need to export this tag and the best way to store the tags is using the JSON file.
Get-AzVM -VMName Testmachine2k12 | Select -ExpandProperty Tags | ConvertTo-Json | Out-File C:\Temp\VMTag.json
You can see the tag file is stored in the C:\temp folder with the VMTag.json file name.
If you want to store the tags in the CSV file format then, we can use the below command.
Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags | ConvertTo-Json | ConvertFrom-Json | Export-Csv C:\Temp\TestMachine2k16tags.csv -NoTypeInformation
The above command will store the azure VM TestMachine2k16 tags to the C:\Temp\TestMachine2k16tags.CSV format.
Advertisements