hi
any idea why I am not getting any output from this?
&{foreach($dc in Get-Datacenter){
foreach($esx in Get-VMHost -Location $dc){
Select @{N='Datacenter';E={$dc.Name}}, @{N='VMhost';E={$esx.Name}}
}}
}
I am connected to all my vcenters
thanks
And for the 2nd one, you have to output the resulting array (+ a few other minor adjustments).
$report = @()
$dcs = get-datacenter
foreach($dc in $dcs){
$esxhosts = get-vmhost -Location $dc | ? {$_.connectedstate -ne "NotResponding"}
foreach ($esx in $esxhosts) {
$info = "" | select Datacenter, VMhost
$info.Datacenter = $dc.Name
$info.VMhost = $esx.Name
$report += $info
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
same with this
$report = @()
$dc = get-datacenter
$esxhosts = get-datacenter| get-vmhost | ? {$_.connectedstate -ne "NotResponding"}
foreach ($esx in $esxhosts) {
$info = "" | select Datacenter, VMhost
$info.Datacenter = $dc.Name
$info.VMhost = $esx.Name
$report += $info
}
no output
You to feed something to the Select-Object, even an empty string will do.
&{foreach($dc in Get-Datacenter){
foreach($esx in Get-VMHost -Location $dc){
"" | Select @{N='Datacenter';E={$dc.Name}}, @{N='VMhost';E={$esx.Name}}
}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And for the 2nd one, you have to output the resulting array (+ a few other minor adjustments).
$report = @()
$dcs = get-datacenter
foreach($dc in $dcs){
$esxhosts = get-vmhost -Location $dc | ? {$_.connectedstate -ne "NotResponding"}
foreach ($esx in $esxhosts) {
$info = "" | select Datacenter, VMhost
$info.Datacenter = $dc.Name
$info.VMhost = $esx.Name
$report += $info
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
awesome thanks Luc