none
Export Azure VM tags to CSV RRS feed

  • Question

  • Hi 

    I am trying to get a script to get the Vm details on my azure tenant including the complete Tags whatever available 
    Currently I am using the below script to get the Vm details But I am not able to extract the Tags  and its contents

    Import-Module -Name Az
    get-azsubscription
    $getallSubscriptions = Get-AzSubscription

    foreach($subscription in $getallSubscriptions)
    {
    Select-AzSubscription $subscription$vms = Get-AzVM
    foreach($vm in $vms)
    { $value = $($subscription.Id) + "," + $($rg.ResourceGroupName)  + "," + $vm.Name + ","  + "," +$vm.Id  Add-content -path "C:\azure-Vm.txt" -value $value

    Can someone please help on this 

    Monday, June 29, 2020 1:34 PM

All replies

  • Hi All 

    I resolved this by myself  :) 

    Import-Module -Name Az
    get-azsubscription
    $getallSubscriptions = Get-AzSubscription

    foreach($subscription in $getallSubscriptions)
    {
    Select-AzSubscription $subscription$vms = Get-AzVM
    foreach($vm in $vms)
    {

    {$TagOut =$nulll

    foreach($tag in $vm.tags.keys)
    {
    $Tagz=$tag+ ":" + $vm.tags.$tag+ ","
    $TagOut=$TagOut+$Tagz
    }  $value = $($subscription.Id) + "," + $($rg.ResourceGroupName)  + "," + $vm.Name + ","  + "," +$vm.Id + "," + $TagOut 

    Add-content -path "C:\azure-Vm.txt" -value $value

    $TagOut will have the complete tags with comma separated 


    • Proposed as answer by KRISHANA KUMAR Wednesday, July 1, 2020 10:00 PM
    Wednesday, July 1, 2020 6:41 AM