Just add the Export-Csv after the last curly brace.
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.network.firewall.ruleset.rule.list.Invoke() |
select @{N = 'VMHost'; E = { $esx.Name } }, RuleSet,
@{N = 'Enabled'; E = { $esxcli.network.firewall.ruleset.list.Invoke(@{rulesetid = "$($_.Ruleset)" }).Enabled } },
Direction, Protocol, PortBegin, PortEnd, PortType,
@{N = 'AllowedIP'; E = { ($esxcli.network.firewall.ruleset.allowedip.list.Invoke(@{rulesetid = "$($_.Ruleset)" })).AllowedIPAddresses -join '|' } }
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture