ONTAP Discussions

When Exporting to CSV I'm receiving System.String[] in spreadsheet

whf_netapp
266 Views

Hello,

 

When I run the following PowerShell command:  Get-NcExportRule -vserver * 

all the columns on the screen populate with the proper information, however when I export it to a .csv file, the columns Protocol, RoRule, RwFule and SuperUser are all populated with System.String[]. 

Anyone have any suggestions?

 

 

1 REPLY 1

HUX20002000
70 Views

That's happening because those columns are arrays rather than strings (hence the curly brackets in the onscreen output) and Export-Csv doesn't know what to do with those. There are various ways to deal with that. I usually use PowerShell custom objects with the 'join' operation for columns that have arrays. For example:

 

$output = @()

$rules = Get-NcExportRule

foreach($rule in $rules)

   {

   $output += [pscustomobject]@{

      'PolicyName' = $rule.PolicyName

      'RuleIndex' = $rule.RuleIndex

      'ClientMatch' = $rule.ClientMatch

      'Protocol' = $rule.Protocol -join(', ')

      # etc.

      }

   }

$output | Export-Csv -Path [\path\to\.csv] -NoTypeInformation

 

So if 'Protocol' for a particular rule shows as '{nfs3, cifs, flexcache}' onscreen (for example), it will display as 'nfs3, cifs, flexcache' in the .csv file.

Public