Automation

 View Only
  • 1.  get-securitypolicy from multiple esxi with host name

    Posted Aug 17, 2022 07:39 PM

    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



  • 2.  RE: get-securitypolicy from multiple esxi with host name

    Posted Aug 17, 2022 08:29 PM

    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


  • 3.  RE: get-securitypolicy from multiple esxi with host name

    Posted Aug 18, 2022 07:46 PM

    Thank you, this is amazing..