You can remove the inner loop in the ConnectedVia relationship and treat the return value of pObj->ConnectedVia as an object handle.
foreach probe (getInstances("Probe")) { pObj = object("Probe", probe); foreach ipNet (pObj->ConnectedVia) { // This returns all of the objects in the ConnectedVia relationshipset if (ipNet->CreationClassName == "IPNetwork") { print(probe . " is ConnectedVia ".ipNet); } } }