Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 214415

Re: Index was outside the bounds of the array - Get-VirtualPortGroup

$
0
0

I have tweaked the script a little. Now, I'm getting data with out any errors..Thank you for your inputs.:)

 

 

#Network Data Array

$NetworkData = @()

 

 

ForEach ($VMHost in Get-VMHost){

$Esx = Get-View -Id $VMHost.id

ForEach($vSwitch in $Esx.Config.Network.Vswitch){

ForEach($PortGroup in ($Esx.Config.Network.Portgroup | where {$_.Vswitch -eq $vSwitch.Key})) {

  $NetworkItems = "" | Select VC, Host, vswitchname , PromiscuousMode , Forgedtransmit , MacChanges , Portgroup,PGPromiscuousMode,

                       PGForgedTransmits, PGMACChanges, NoNativeVlan1, NoReservedVlan, NoVGTvlan4095, LabelVswitches  

 

 

    $NetworkItems.VC = $vCenterInstanceName

    $NetworkItems.Host = $VMHost

    $NetworkItems.vswitchname = $vSwitch.Name

    $NetworkItems.PromiscuousMode = &{if($vSwitch.Spec.Policy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}}

    $NetworkItems.Forgedtransmit = &{if($vSwitch.Spec.Policy.Security.ForgedTransmits){"Accept"} Else {"Reject"}}

    $NetworkItems.MacChanges = &{if($vSwitch.Spec.Policy.Security.MacChanges){"Accept"} Else {"Reject"}}

    $NetworkItems.Portgroup = $PortGroup.Spec.Name

    $NetworkItems.PGPromiscuousMode = &{if($PortGroup.ComputedPolicy.Security.AllowPromiscuous -eq $null) {if($vSwitch.Spec.Policy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}} Else {if($PortGroup.ComputedPolicy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}}}

    $NetworkItems.PGForgedTransmits = &{if($PortGroup.ComputedPolicy.Security.ForgedTransmits -eq $null)  {if($vSwitch.Spec.Policy.Security.ForgedTransmits)  {"Accept"} Else {"Reject"}} Else {if($PortGroup.ComputedPolicy.Security.ForgedTransmits)  {"Accept"} Else {"Reject"}}}

    $NetworkItems.PGMACChanges = &{if($PortGroup.ComputedPolicy.Security.MacChanges -eq $null)  {if($vSwitch.Spec.Policy.Security.MacChanges)  {"Accept"} Else {"Reject"}} Else {if($PortGroup.ComputedPolicy.Security.MacChanges)  {"Accept"} Else {"Reject"}}}

    $NetworkItems.NoNativeVlan1 = &{if($PortGroup.Spec.VLANID -eq 1) {"Accept"} Else {"Reject"}}

    $NetworkItems.NoReservedVlan = &{if(($PortGroup.Spec.VLANID -ge 3968 -and $PortGroup.Spec.VLANID -le 4047) -or ($PortGroup.Spec.VLANID -eq 4094)) {"NonReject"} Else {"Compliant"}}

    $NetworkItems.NoVGTvlan4095 = &{if($PortGroup.Spec.VLANID -eq 4095){"NonReject"} Else {"Reject"}}

    $NetworkItems.LabelVswitches = &{if (!$vSwitch.Name) {"NonReject"} Else {"Reject"}}

    $NetworkData += $NetworkItems

  

  

 

}}}

 

 

#Export the data to CSV sheet . Ensure the directory exists

   $NetworkData | Export-Csv -NoTypeInformation -UseCulture -Path "C:\TSRReport\$($FileName)"


Viewing all articles
Browse latest Browse all 214415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>