Modified the script like below
&{foreach($sw in (Get-VirtualSwitch -Standard)){
foreach($VPG in &{
Get-Process -Id $PID
Try {
Get-VirtualPortGroup -VirtualSwitch $sw
}
Catch {
Get-Process -Id $PID
$_ | Select *
$_.Exception.InnerException | Select *
}}){
$VPG |
Select @{N="Host";E={$sw.VMHost.Name}},
@{N="Switch";E={$sw.Name}},
@{N="Promiscuous mode";E={if($sw.Extensiondata.Spec.Policy.Security.AllowPromiscuous) {"NonCompliant"} Else {"Complaint"}}},
@{N="Forged transmits";E={if($sw.Extensiondata.Spec.Policy.Security.ForgedTransmits){"NonCompliant"} Else {"Complaint"}}},
@{N="MAC Changes";E={if($sw.Extensiondata.Spec.Policy.Security.MacChanges){"NonCompliant"} Else {"Complaint"}}},
@{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) {"NonCompliant"} Else {"Complaint"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.AllowPromiscuous) {"NonCompliant"} Else {"Complaint"}}}},
@{N="Portgroup Forged transmits";E={if($VPG.Extensiondata.Spec.Policy.Security.ForgedTransmits -eq $null) {if($sw.Extensiondata.Spec.Policy.Security.ForgedTransmits) {"NonCompliant"} Else {"Complaint"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.ForgedTransmits) {"NonCompliant"} Else {"Complaint"}}}},
@{N="Portgroup MAC Changes";E={if($VPG.Extensiondata.Spec.Policy.Security.MacChanges -eq $null) {if($sw.Extensiondata.Spec.Policy.Security.MacChanges){"NonCompliant"} Else {"Complaint"}} Else {if($VPG.Extensiondata.Spec.Policy.Security.MacChanges){"NonCompliant"} Else {"Complaint"}}}},
@{N="NoNativeVlan1";E={if($VPG.vLanID -eq 1) {"NonCompliant"} Else {"Complaint"}}},
@{N="NoReservedVlans";E={if(($VPG.vLanID -ge 3968 -and $VPG.vLanID -le 4047) -or ($VPG.vLanID -eq 4094)) {"NonComplaint"} Else {"Compliant"}}},
@{N="NoVGTvlan4095";E={if($VPG.vLanID -eq 4095){"NonComplaint"} Else {"Complaint"}}},
@{N="LabelVswitches";E={if (!$vSwitch.Name) {"NonComplaint"} Else {"Complaint"}}}
}}} | Export-CSV C:\CatchNetworkreport.csv -NoTypeInformation -UseCulture
Couldn't able to get process ID info and couldn't able to catch exception. The same error message we got.