Ok, perhaps I wasn't too clear.
The intention was that you insert those lines in your original script, and that we could monitor the increasing consumption of PM and catch the exception when it goes wrong.
Something like this
&{foreach($swin (Get-VirtualSwitch-Standard)){
foreach($VPGin&{
Get-Process-Id$PID
Try {
Get-VirtualPortGroup-VirtualSwitch$sw
}
Catch {
Get-Process-Id$PID
$_|Select*
$_.Exception.InnerException|Select*
}}){
$VPG
# The rest of your original script
}}}