VMware Cloud Community
vmdkness
Enthusiast
Enthusiast
Jump to solution

Export-csv system.string[] issue

I have a powercli script I wrote to gather virtual switch and portgroup information.

Most of it works however the active and standby nic information shows up fine in the console

For example ActiveNic  : {vmnic4}

However in the csv file it shows up  as @{ActiveNic=System.String[]} without the actual vmnic information

Please let me know how to get the  active and standby vmnic info into the csv file here is the script

Connect-VIServer vcenter

$report = @()

$ESXhosts =  Get-VMHost

foreach ($esxhost in $ESXhosts) {

      $Vswitches = $esxhost | Get-Virtualswitch

            foreach($vswitch in $vswitches){

            $Portgroups= $vswitch | Get-VirtualPortGroup

                  foreach ($portgroup in $Portgroups){

                        $nicteam= Get-NicTeamingPolicy $portgroup

                        $row = "" | select Cluster, Esxhost, Vswitch, Portgroup,Vlan,ActiveNic,Standbynic

                        $row.Cluster = $esxhost.Parent

                        $row.ESxhost = $esxhost.name

                        $row.Vswitch = $Vswitch.Name

                        $row.portgroup = $portgroup.name

                        $row.Vlan = $portgroup.Vlanid

                        $row.Activenic=$nicteam.activenic

                        $row.Standbynic=$nicteam.StandbyNic

                        $report += $row}

                        }

                        }

            $report | Export-Csv c:\psresults\host_portgroups_clustr_standby.csv

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Export-Csv cmdlet can handle properties that are arrays or complex objects correctly.

A way around this is to convert the array to a single string.

Something like this

Connect-VIServer vcenter
$report = @() $ESXhosts = Get-VMHost
foreach ($esxhost in $ESXhosts) {   $Vswitches = $esxhost | Get-Virtualswitch
 
foreach($vswitch in $vswitches){     $Portgroups = $vswitch | Get-VirtualPortGroup
   
foreach ($portgroup in $Portgroups){       $nicteam = Get-NicTeamingPolicy $portgroup
      $row = "" | select Cluster, Esxhost, Vswitch, Portgroup,Vlan,ActiveNic,Standbynic
     
$row.Cluster = $esxhost.Parent
      $row.ESxhost = $esxhost.name
    
$row.Vswitch = $Vswitch.Name
      $row.portgroup = $portgroup.name
      $row.Vlan = $portgroup.Vlanid
      $row.Activenic= [string]::Join(',',$nicteam.activenic)       $row.Standbynic=[string]::Join(',',$nicteam.StandbyNic)       $report += $row}   } } $report | Export-Csv c:\psresults\host_portgroups_clustr_standby.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The Export-Csv cmdlet can handle properties that are arrays or complex objects correctly.

A way around this is to convert the array to a single string.

Something like this

Connect-VIServer vcenter
$report = @() $ESXhosts = Get-VMHost
foreach ($esxhost in $ESXhosts) {   $Vswitches = $esxhost | Get-Virtualswitch
 
foreach($vswitch in $vswitches){     $Portgroups = $vswitch | Get-VirtualPortGroup
   
foreach ($portgroup in $Portgroups){       $nicteam = Get-NicTeamingPolicy $portgroup
      $row = "" | select Cluster, Esxhost, Vswitch, Portgroup,Vlan,ActiveNic,Standbynic
     
$row.Cluster = $esxhost.Parent
      $row.ESxhost = $esxhost.name
    
$row.Vswitch = $Vswitch.Name
      $row.portgroup = $portgroup.name
      $row.Vlan = $portgroup.Vlanid
      $row.Activenic= [string]::Join(',',$nicteam.activenic)       $row.Standbynic=[string]::Join(',',$nicteam.StandbyNic)       $report += $row}   } } $report | Export-Csv c:\psresults\host_portgroups_clustr_standby.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vmdkness
Enthusiast
Enthusiast
Jump to solution

Once again Lucd you saved me a whole bunch of time it works great

thanks

0 Kudos