Quantcast
Viewing all articles
Browse latest Browse all 21975

When Value contains multiple values convertto-html will return system.object[] and not value

What I'm trying to do is build a function to pull networking values from some ESXi hosts. The function works correctly, but when I try to convertto-html values that contain more then one entry returns the result system.object[]

Function get-vmnetworking
{

param
(
  [Parameter(ValueFromPipelineByPropertyName=$true)]$Name
)

$i = 0
$Output = @()
$itemCount=$input.Count

    $Input | ForEach {

        Write-Progress -activity "Getting Networking Information" -status $_ -PercentComplete (($i++ / $itemCount)  * 100)

$temp = (get-vmhost $_ | Get-VMHostNetworkAdapter )

$object = New-Object PSObject

$object | Add-Member NoteProperty "Host"         $_
$object | add-member NoteProperty "MGMT IP"      ($temp | ? {$_.ManagementTrafficEnabled -eq $True} | Select-object -ExpandProperty IP)
$object | add-member NoteProperty "MGMT MTU"     ($temp | ? {$_.ManagementTrafficEnabled -eq $True} | Select-object -ExpandProperty MTU)
$object | add-member NoteProperty "VMotion IP"   ($temp | ? {$_.VMotionEnabled -eq $True} | Select-Object -ExpandProperty IP)
$object | add-member NoteProperty "VMotion MTU"  ($temp | ? {$_.VMotionEnabled -eq $True} | Select-Object -ExpandProperty MTU)
$object | add-member NoteProperty "StorageIP"   ($temp | ? {$_.ManagementTrafficEnabled -eq $False -and $_.VMotionEnabled -eq $false -and $_.FaultToleranceLoggingEnabled -eq $false} | Select-Object -ExpandProperty IP)
$object | add-member NoteProperty "StorageMTU"  ($temp | ? {$_.ManagementTrafficEnabled -eq $False -and $_.VMotionEnabled -eq $false -and $_.FaultToleranceLoggingEnabled -eq $false} | Select-Object -ExpandProperty MTU)

$Output += $object

    } # End For Each Loop

$Output

} # End of set-vmnetworking

Running the command

get-vmhost | sort-object Name | get-vmnetworking

Will return the result

MGMT IP     : 192.168.100.24
MGMT MTU    : 1500
VMotion IP  : 192.168.102.24
VMotion MTU : 1500
StorageIP   : {192.168.101.24, 192.168.101.27}
StorageMTU  : {1500, 1500}

As you can see the results Storage IP and Storage MTU are contained within brackets because they have multiple values.

If I were to convertto-html

$frag0 = get-vmhost | get-vmnetworking | convertto-html -as Table -Fragment -PreContent '<H2>Networking Information</H2>' | out-string

Convertto-html $style -PostContent $frag0 | out-file $output\file.html

The outputted html file will replace the multiple values as System.Object[]

Any help would be appreciated.


Walter


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>