I want to Print ESXI/ VM's information in below format.
some how i was able to get 4 columns , but coloum-3 (vc_vm_list) i have requirement like Json ArrayList
vc_vm_list" : [ "server01.cloud.org", "edge-02-abc", "edge-02-abc" ],
below is my code which work fo4 rest 4 columns
Try like this
Get-VM |
Select-Object @{Name = "bp_host"; Expression = { $_.VMHost.Name.Split('.')[0] } },
@{Name = "vc_vcenter_server"; Expression = { ([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{Name = "vc_vm_list"; Expression = { (Get-VM -Location $_.VMHost).Name | ConvertTo-Json } },
@{Name = "vc_cluster"; Expression = { (Get-Cluster -VM $_).Name } },
@{Name = 'z_vcenter_vms'; Expression = { 'enrichment' } } |
Sort-Object -Property bp_host |
Export-Csv -Path "{{ my_folder }}\\{{ my_esxi_file }}" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
@{Name = "vc_vm_list"; Expression = { """$((Get-VM -Location $_.VMHost).Name -join '|')""" } },
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
Get-VM |
Select-Object @{Name = "bp_host"; Expression = { $_.VMHost.Name.Split('.')[0] } },
@{Name = "vc_vcenter_server"; Expression = { ([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{Name = "vc_vm_list"; Expression = { (Get-VM -Location $_.VMHost).Name | ConvertTo-Json } },
@{Name = "vc_cluster"; Expression = { (Get-Cluster -VM $_).Name } },
@{Name = 'z_vcenter_vms'; Expression = { 'enrichment' } } |
Sort-Object -Property bp_host |
Export-Csv -Path "{{ my_folder }}\\{{ my_esxi_file }}" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This looks better
but if we can remove the “newline” (\nl, CR/LF) after each VM listed ?
Try replacing that line with
@{Name = "vc_vm_list"; Expression = { ((Get-VM -Location $_.VMHost).Name | ConvertTo-Json).Replace("`r`n",'') } },
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Can we also format the column as follows, put the entire entry in double-quotes and each item separated by a pipe
vc_vm_list
---------
"server01.cloud.org|edge-02-abc|edge-02-abc"
Try like this
@{Name = "vc_vm_list"; Expression = { """$((Get-VM -Location $_.VMHost).Name -join '|')""" } },
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference