I created the below script in order to collect information regarding the Firewall service, unfortunately I got an empty CSV, not sure what I'm missing
Are you running this against multiple vCenters?
That loop over the content of $vCenterServerListing is not required.
Also, there is no need to explicitly load a module.
Try something like this
$vCenter = Read-Host "Please entrer vCenter FQDN or IP"
$credential = Get-Credential
Connect-VIServer -Server $vCenter -Credential $credential
Get-VMHost -PipelineVariable esx | ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.network.firewall.ruleset.rule.list.Invoke() |
Select-Object @{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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you running this against multiple vCenters?
That loop over the content of $vCenterServerListing is not required.
Also, there is no need to explicitly load a module.
Try something like this
$vCenter = Read-Host "Please entrer vCenter FQDN or IP"
$credential = Get-Credential
Connect-VIServer -Server $vCenter -Credential $credential
Get-VMHost -PipelineVariable esx | ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.network.firewall.ruleset.rule.list.Invoke() |
Select-Object @{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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I got it, it's working fine and I understand my mistake. thanks 🙂