Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 232319

Re: Assign Port Group to VM. I am getting error.

$
0
0

Hi,

 

You cannot directly assign a string value to an object; instead, you should add some code to search for an object of the given type with such name.

 

So, in your case, you can replace

 

dvPortgroup = "test (dvSwitch)";

 

with

 

dvPortgroup = null;
var alldvpg = Server.findAllForType("VC:DistributedVirtualPortgroup");
for each (var pg in alldvpg) {  if (pg.name == "test (dvSwitch)") {    dvPortgroup = pg;    break;  }
}

if (!dvPortgroup) {
  System.error("Can't find the given portgroup");
}

 

What this code does is to iterate over all available distributes virtual portgroups and to check if the name of some portgroup matches the desired name. If a match is found, it assigns the found object to your dvPortgroup attribute; if no match is found, it prints an error message.

 

In production, you may want to implement a more sophisticated search logic, but the main idea is the same - you cannot assign strings to objects, you should search for objects matching some criteria.


Viewing all articles
Browse latest Browse all 232319

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>