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
You could something like this
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
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
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
You could something like this
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
Hi LucD,
Thank you very much for the swift response. It works
-JD
Hi LucD,
Can you please help me if we can import Tag Category too as a column in the script?
You could do something like this
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
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 |