I'm hoping someone here can help me out with this. I'm trying to build a report that will list all the route information for a series of hosts in a report.
What I am trying to do is get a readable report thats simliar to the data thats returned from either "esxcfg-route -l"; or "get-vmhostroute". The part that I am struggling with is the fact that each host returns multiple lines, and for the life of me I can't figure out a simple way to put all of them into an array.
What I would like to see on the output is something like:
clustername, vmhost, destination, gateway
ie
cluster1,vmhost1.domain.com,0.0.0.0/0,10.10.10.1
,,,10.101.106.0/25,0.0.0.0
(etc, for every 'hit')
Here is the script that I have thus far. I know that part of the issue is that I need to expand the array; but thats the part I am struggling with :-) Odds are I am just over complicating this and there is a simple solution that just escapes me.
# Define all VC instances as variables to call later
$vc1 = "VC-SERVER1"
$vc2 = "VC-SERVER2"
# Set PowerCLI to multiple
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false
connect-VIServer -Server $vc1, $vc2
$report = @()
$clusters = get-cluster |sort name
foreach ($cluster in $clusters) {
foreach ($ESXHost in Get-Cluster $cluster |Get-VMHost |sort name ) {
$Row = "" | Select-Object Cluster,ESXHost,Destination,Gateway
$Row.Cluster = $cluster.name
$Row.ESXHost = $ESXHost.name
$Row.Destination = @($ESXHost |get-vmhostroute)
$Row.gateway = @($ESXHost |get-vmhostroute)
$Report += $Row
}
}
Any help is greatly appreciated!