ONTAP Discussions
ONTAP Discussions
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?
Solved! See The Solution
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.
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.
Thank you very much. This worked perfectly and I learned something.