Automation

 View Only
  • 1.  Export vm tags and vm inventory details together

    Posted Mar 13, 2019 12:37 PM

    Hi experts,

    We have a requirement to export the get-vm and all the tags associated to the vms into a single csv file. I managed to get the inventory dump using get-vm as below and it works,. However I am not able to export the vm tags information. Even if I run it manually it shows raw data and its not aligned. Can you please help us to get these information at once in a script ?

    Get-VM | Select-object Name,@{N='vCenter';E={([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}}, PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost, Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB | Export-Csv -path “c:\vc_inv.csv” –NoTypeInformation

    Requirement:

    all vm related information

    all tags associated to the vms

    Thanks a lot in advance



  • 2.  RE: Export vm tags and vm inventory details together

    Posted Mar 13, 2019 12:48 PM

    Can you expand a bit on what you want to see? Only the Tags or TagCategory/Tag?

    And how would you include that in a report? In one column?

    Not sure what you mean with "...raw data and its not aligned"



  • 3.  RE: Export vm tags and vm inventory details together

    Posted Mar 13, 2019 01:08 PM

    Hi LucD,

    We want to export the tag\tagcategory for each vm. This information is to capture the backup related tags for our backup software and to update the cmdb.

    The results can be dumped in a csv format in columns

    VMname | Assigned Tag | Category ( something like this )

    Thanks

    JD



  • 4.  RE: Export vm tags and vm inventory details together
    Best Answer

    Posted Mar 13, 2019 01:24 PM

    You could something like this

    Get-VM |

    Select-object Name,

       @{N = 'vCenter'; E = {([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}},

       @{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}},

       PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost,

       Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB |

    Export-Csv -path “c:\Temp\vc_inv.csv” –NoTypeInformation -UseCulture



  • 5.  RE: Export vm tags and vm inventory details together

    Posted Mar 13, 2019 02:05 PM

    Hi LucD,

    Thank you very much for the swift response. It works

    -JD



  • 6.  RE: Export vm tags and vm inventory details together

    Posted May 07, 2020 08:34 PM

    Hi LucD,

    Can you please help me if we can import Tag Category too as a column in the script?



  • 7.  RE: Export vm tags and vm inventory details together

    Posted May 07, 2020 08:47 PM

    You could do something like this

    Get-VM |

    Select-object Name,

       @{N = 'vCenter'; E = {([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}},

       @{N='TagCategories';E={

        $script:assigned = Get-TagAssignment -Entity $_

        $script:assigned.Tag.Category.Name -join '|' }},

       @{N = 'Tags'; E = {$script:assigned.Name -join '|'}},

       PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost,

       Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB |

    Export-Csv -path “c:\Temp\vc_inv.csv” –NoTypeInformation -UseCulture



  • 8.  RE: Export vm tags and vm inventory details together

    Posted May 07, 2020 10:38 PM

    Hi LucD,

    This code worked for both the columns Tags and Category.

    Get-VM |

      

       Select-object Name,

       @{N = 'vCenter'; E = {([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}},

       @{N='TagCategories';E={

        $script:assigned = Get-TagAssignment -Entity $_

        $script:assigned.Tag.Category.Name -join '|' }},

       @{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}},

       PowerState, Folder, VMHost, Notes |