Hi All
I have a script when executed produces results like below.
foreach ($Adminserver in $Adminservers){
$hypervischeck = Get-BrokerHypervisorConnection -AdminAddress $Adminserver
$HypervisorStatus += New-Object -TypeName PSObject -Property @{Sitename = $Adminserver
HypervisorName = $hypervischeck.Name
Status = $hypervischeck.State
}}
The out put is like below
Sitename Status HupervisorName
Example1.com {ON,ON,ON} {VC1,VC2,VC3}
Example2.com {ON,ON,ON} {VC4,VC4,VC5}
When I covert these output to html format I am getting below results , Status and HypervisorName values are showing as System.object.
Could some one please help me wit this script. Thanks .
@{Sitename=example1.com; Status=System.Object; HypervisorName=System.Object; Value=}
@{Sitename=example2.com; Status=System.Object; HypervisorName=System.Object; Value=}
Since your Get-BrokerHypervisorConnection is returning multiple objects you should also loop through each of those objects within the for each $adminservers loop.
The $hypervischeck variable contains an object with each hypervisor. By doing object.property, Powershell v3 and above will do an implicit foreach loop, basically assuming that you want to do:
$hypervischeck | foreach{$_.Name}
This creates an array which is the behavior you are seeing. You need to add an explicit for loop to enumerate through each hypervisor:
$HypervisorStatus = foreach ($Adminserver in $Adminservers){
$hypervischeck = Get-BrokerHypervisorConnection -AdminAddress $Adminserver
foreach ($hypervisor in $hypervischeck) {
New-Object -TypeName PSObject -Property @{Sitename = $Adminserver
HypervisorName = $hypervisor.Name
Status = $hypervisor.State}
} #foreach $hypervisor
} #foreach $Adminserver
Another note, rather than doing $var=@() and then doing $var += New-Object, assign the variable to the for loop and it will be automatically appended into the varaible.
Hi Rob/Peter
Thanks for taking your valuable time to help . I am able to produce the output how I wanted and thanks for the hint . Its really helpful and I learned something new.
I was breaking my head for quite some time to get this working
Thanks once again .