Hi,
We have developed a script to get the Virtual Network info. For small environment the script working fine but huge environment we are getting error message. Any inputs are appreciated.
Get-VirtualPortGroup : 8/19/2013 11:01:52 PM Get-VirtualPortGroup Index was outside the bounds of the array.
At C:\IA\Requests\Request#14 TSRStatus\NetworkHardeningLatest.ps1:21 char:40
+ foreach($VPG in (Get-VirtualPortGroup <<<< -VirtualSwitch $sw)) { $VPG |
+ CategoryInfo : NotSpecified: (:) [Get-VirtualPortGroup], ViErro
r
+ FullyQualifiedErrorId : Client20_VMHostServiceImpl_GetVirtualPortGroup_B
yVirtualSwitch_GetPortGroupNames_ViError,VMware.VimAutomation.ViCore.Cmdle
ts.Commands.Host.GetVirtualPortGroup
The script is given below
&{foreach($sw in (Get-VirtualSwitch -Standard)){
foreach($VPG in (Get-VirtualPortGroup -VirtualSwitch $sw)) { $VPG |
Select @{N="Host";E={$sw.VMHost.Name}},
@{N="Switch";E={$sw.Name}},
@{N="Promiscuous mode";E={if($sw.Extensiondata.Spec.Policy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}}},
@{N="Forged transmits";E={if($sw.Extensiondata.Spec.Policy.Security.ForgedTransmits){"Accept"} Else {"Reject"}}},
@{N="MAC Changes";E={if($sw.Extensiondata.Spec.Policy.Security.MacChanges){"Accept"} Else {"Reject"}}},
@{N="Portgroup";E={$VPG.Name}},
@{N="Portgroup Promiscuous mode";E={if($VPG.Extensiondata.Spec.Policy.Security.AllowPromiscuous -eq $null) {if($sw.Extensiondata.Spec.Policy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.AllowPromiscuous) {"Accept"} Else {"Reject"}}}},
@{N="Portgroup Forged transmits";E={if($VPG.Extensiondata.Spec.Policy.Security.ForgedTransmits -eq $null) {if($sw.Extensiondata.Spec.Policy.Security.ForgedTransmits) {"Accept"} Else {"Reject"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.ForgedTransmits) {"Accept"} Else {"Reject"}}}},
@{N="Portgroup MAC Changes";E={if($VPG.Extensiondata.Spec.Policy.Security.MacChanges -eq $null) {if($sw.Extensiondata.Spec.Policy.Security.MacChanges){"Accept"} Else {"Reject"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.MacChanges){"Accept"} Else {"Reject"}}}},
@{N="NoNativeVlan1";E={if($VPG.vLanID -eq 1) {"Accept"} Else {"Reject"}}},
@{N="NoReservedVlans";E={if(($VPG.vLanID -ge 3968 -and $VPG.vLanID -le 4047) -or ($VPG.vLanID -eq 4094)) {"Accept"} Else {"Reject"}}},
@{N="NoVGTvlan4095";E={if($VPG.vLanID -eq 4095){"Accept"} Else {"Reject"}}},
@{N="LabelVswitches";E={if (!$vSwitch.Name) {"Accept"} Else {"Reject"}}}
}}} | Export-CSV C:\Report\Networkreport.csv -NoTypeInformation -UseCulture
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.1 Release 2 build 1012425
---------------
Snapin Versions
---------------
VMWare AutoDeploy PowerCLI Component 5.1 build 768137
VMWare ImageBuilder PowerCLI Component 5.1 build 768137
VMware vCloud Director PowerCLI Component 5.1 build 1012427
VMware License PowerCLI Component 5.1 build 669840
VMware VDS PowerCLI Component 5.1 build 1012428
VMware VDS vSphere PowerCLI Component 4.1.1 build 000001
VMware vSphere PowerCLI Component 5.1 build 1012428
Thanks