JagadeeshDev
Hot Shot
Hot Shot

Export vm tags and vm inventory details together

Jump to solution

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

http://www.myitblog.in/
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership

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"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JagadeeshDev
Hot Shot
Hot Shot

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

http://www.myitblog.in/
0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
JagadeeshDev
Hot Shot
Hot Shot

Hi LucD,

Thank you very much for the swift response. It works

-JD

http://www.myitblog.in/
0 Kudos
Kumar_Chidi
Contributor
Contributor

Hi LucD,

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

0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Kumar_Chidi
Contributor
Contributor

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 |

0 Kudos