Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 219257

Export Tags and Notes in to a single CSV

$
0
0

I am attempting to export tags and notes in to a single CSV for batch modification and importing back in to vCenter.  I have a script to export tags and I can export notes, but I want it to be in a single operation and in to a single CSV.  Below is the current code I am using and please forgive me for not crediting the original creator I built this script from as I do not remember!  I get a Notes column in the resulting CSV but it is empty...  Thanks in advance.

 

Don

 

Current script:

 

if (-not $DefaultVIServer.IsConnected) {

    Connect-VIServer "vcenter.server" -Credential (Get-Credential $_.Username)

}

 

$tagCat = @()

$tagTab = @{}

 

foreach($tag in (Get-TagAssignment)){

    $tagCat += $tag.Tag.Category.Name

    $key = $tag.Entity.Name

    if($tagTab.ContainsKey($key)){

    ` $val = $tagTab.Item($key) 

    }

    else{

        $val = @{}

    }

    $val.Add($tag.Tag.Category.Name,$tag.Tag.Name)

    $tagTab[$key] = $val

}

 

$tagCat = $tagCat | Sort-Object -Unique

 

$tags = foreach($row in ($tagTab.GetEnumerator() | Sort-Object -Property Key)){

    $VMName = $row.Key

    $VMNotes = Get-VM $VMName | Select-Object -ExpandProperty Notes

    $obj = New-Object PSObject -Property @{

        Name = $row.Key

    }

    $tagCat | %{

        $obj | Add-Member -Name $_ -Value $row.Value[$_] -MemberType NoteProperty

    }

    $VMNotes | %{

        $obj | Add-Member -Name "Notes" -Value $row.$VMNotes -MemberType NoteProperty

    }

    $obj

}

 

$tags | Export-Csv tags.csv -NoTypeInformation -UseCulture


Viewing all articles
Browse latest Browse all 219257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>