Automation

 View Only
  • 1.  Export virtuals with Tags to CSV file

    Posted Dec 03, 2021 05:42 AM

    Seems easy, and I can get the data I need, I just cannot get it into the CSV file the way I want. Here's what I'm looking for:

    CSV file format:

    VM_Name, Tag#1, Tag#2, Tag#3, Tag#n

    The CSV file should have all virtuals in the vCenter, and include all tags against each virtual, one per column- this last bit is giving me headaches!

    I've got the following code & outputs:

    Script #1:

     

     

    Output:

     

    #TYPE Selected.System.String
    Length
    29
    29
    29
    29
    29
    29

    Script #2:

     

     

    Output:

    CRPsldcp01 MyvCenter01 Company.operations.customer.code/CRP, Company.operations.object.status/decommissioned, Company.operations.server.role/scilodc

     

    Problem is that the tags are all in one column.

    Script #3:

     

     

    Output:

    CRPsldcp01 CRP decommissioned scilodc

    Problem is that the tags are all in one column.

     

    Can someone help me out to extract the tags into separate columns pls?

     

     

     

     

     

     



  • 2.  RE: Export virtuals with Tags to CSV file

    Posted Dec 03, 2021 07:55 AM

    You could do something like this



  • 3.  RE: Export virtuals with Tags to CSV file

    Posted Dec 08, 2021 05:38 AM

    Thanks LucD,

    Very nice script however it did not present the Categories & Tags as I would hoped for. The result looked like this:

    VM, tag#1, tag#2

    VMName1, x
    VMName2, , x

    So based on your gr8 work, I modified the script a bit to give me what I wanted:

    VM, Category#1, Category#2

    VMName1, TagName01
    VMName2,     , TagName02
    VMName3, TagName01

    And now I'm happy. Although, my changes may be doing superfluous actions, specifically this section of code which adds the Categories to the top of the table as this code seems to be cycling thru everytime a new VM is processed:

    Please let me know if the code can be made more efficient as I still don't understand how this part works. Here's the full code which I modified:

    Thanks again for helping out!



  • 4.  RE: Export virtuals with Tags to CSV file

    Posted Dec 08, 2021 07:16 AM

    Ok, so you want the Category as the column header, but what if a VM has multiple Tags in the same Category?



  • 5.  RE: Export virtuals with Tags to CSV file
    Best Answer

    Posted Dec 08, 2021 12:19 PM

    This should take care of multiple tags in the same category



  • 6.  RE: Export virtuals with Tags to CSV file

    Posted Dec 08, 2021 11:37 PM

    I did not consider multiple tags in the same Category as my tags are one-2-one with Categories- it's just how it worked out! But your changes makes the code fool-proof. Thank you so much for your help.