Minor thing, but perhaps cache `networks` outside of the loop?  I think we've learned that vSphere queries are expensive :)