This question is probably answered numerous times but I have a hard time figuring the answer, so here it is.
Often time I need to combine multiple get statements into the output, for exmaple, Get-NetworkAdapter and Get-VMHostSysLogServer. These get statement do not have the vm or host on the output. How can aggregiate the vm name and host name in the output? For instance:
Get-VMHostSysLogServer would generate -
Host
----
10.10.10.1
How can I append the ESX host column in the output?
Esx Host
--- ----
ESX1 10.10.10.1
This is the closest way I have, but I am sure there is a more elegant way to do it.
(get-vmhost esx04t).Name;(Get-VMHostSysLogServer -vmhost esx04t).Host
You could do something like this
Get-VMHost esx04t |
Select Name,
@{N="Syslog Server";E={Get-VMHostSysLogServer -vmhost $_ | Select -ExpandProperty Host}}
With a claculated property you can go a long way
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks!
To have vm name or vm hostname display on the first column, does that mean get-vm or get-vmhost should always be on the first line?
Not really, the order of the columns corresponds with the order of the properties on the Select cmdlet.
For example, if you run those lines like this
Get-VMHost esx04t |
Select @{N="Syslog Server";E={Get-VMHostSysLogServer -vmhost $_ | Select -ExpandProperty Host}},Name
the columns will be swapped.
The properties you "select" need of course to be present in the object or be able to to get retrieved based on a property of the object that was passed. For the Syslog Server, we used the host object as an argument on the Get-VMHostSyslogServer cmdlet and extracted the Host property from the object that this cmdlet returned.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the explaination.
For some reason, set-VMHostSysLogServer does not reflect the changes. I have reloaded the syslog daemon, set-VMHostSysLogServer reports the updated changes but not in vCenter.
foreach ($esxhost in (Get-Cluster -Name $cluster | Get-VMHost )){
Write-Host "ESX: $esxhost"
$esxcli = Get-EsxCli -VMhost $esxhost
$esxcli.system.syslog.reload()
}
Is the new value visible in vCenter after a restart of the management service
Get-VMHostService -VMHost $esxHost |
where {$_.Key -eq "vpxa"} |
Restart-VMHostService -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference