VMware Cloud Community
NeoKumar
Enthusiast
Enthusiast

get-securitypolicy from multiple esxi with host name

Hi team,
below script to find the security policy on each esxi host in vcenter, i added a filter, where am looking for "Security" in Portgroup Name and then return the output. but the script is not showing cluster name,hostname. only showing portgroup name and security policys

PS C:\> Get-Cluster |Get-VMHost | Get-VirtualPortGroup | Where {$_.Name -match "Load"} | Get-SecurityPolicy

VirtualPortGroup AllowPromiscuous ForgedTransmits MacChanges
---------------- ---------------- --------------- ----------
Subnet-10.x.x.x_Security True True True
Subnet2-10.x.x.x_Security True True True

=====

need help to get output to file, like:

ClusterName  ESXiName VirtualPortGroup  AllowPromiscuous  ForgedTransmits  MacChanges

cluster1                esxi01  Subnet-10.x.x.x_Security  True                  False                     False

cluster1                esxi01  Subnet2-10.x.x.x_Security  True                  False                     False

0 Kudos
2 Replies
LucD
Leadership
Leadership

You can use the PipelineVariable and some calculated properties on a Select-Object.
Something like this

Get-Cluster -PipelineVariable cluster |
Get-VMHost -PipelineVariable esx |
Get-VirtualPortGroup -PipelineVariable pg |
Where-Object { $_.Name -match "Load" } |
Get-SecurityPolicy |
Select-Object @{N = 'ClusterName'; E = { $cluster.Name}},
  @{N='ESXiName';E={$esx.Name}},
  @{N='VirtualPortGroup';E={$pg.Name}},
  AllowPromiscuous, ForgedTransmits, MacChanges |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

NeoKumar
Enthusiast
Enthusiast

Thank you, this is amazing..

Tags (1)
0 Kudos