Need to help to convert array of strings to html format

Welcome Forums General PowerShell Q&A Need to help to convert array of strings to html format

This topic contains 3 replies, has 3 voices, and was last updated by

3 years, 7 months ago.

  • Author
  • #28972

    Points: 4
    Rank: Member

    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 {ON,ON,ON} {VC1,VC2,VC3} {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 .

    @{; Status=System.Object[]; HypervisorName=System.Object[]; Value=}
    @{; Status=System.Object[]; HypervisorName=System.Object[]; Value=}

  • #28992

    Points: 62
    Rank: Member

    Since your Get-BrokerHypervisorConnection is returning multiple objects you should also loop through each of those objects within the for each $adminservers loop.

  • #28993

    Points: 638
    Helping Hand
    Rank: Major Contributor

    The $hypervischeck variable contains an object with each hypervisor. By doing, 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.

  • #29039

    Points: 4
    Rank: Member

    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 .

The topic ‘Need to help to convert array of strings to html format’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort