I have a functional vro workflow that changes all the ESXI root passwords for a given input vCenter. Works fine, however I want to exclude certain hosts that match a string "mgt" in their hostnames. I can't figure out the jScript code to do this. I would think it would be something in my var statement....
Try this?
var hosts = vcenter.allHostSystems;
for (var h in hosts) {
var host = hosts[h];
System.log("ESXi Host " + host.name + ":");
// test the name does NOT have mgt in it
if(host.name.indexOf("mgt") == -1)
{
var specAccount = new VcHostAccountSpec();
specAccount.id = username;
specAccount.password = password;
host.configManager.accountManager.updateUser(specAccount);
}
}
var hosts = vcenter.allHostSystems;
for (var h in hosts) {
var host = hosts[h];
System.log("ESXi Host " + host.name + ":");
// test the name does NOT have mgt in it
if(host.name.indexOf("mgt") == -1)
{
var specAccount = new VcHostAccountSpec();
specAccount.id = username;
specAccount.password = password;
host.configManager.accountManager.updateUser(specAccount);
}
else
{
System.log("Skipping MGT host " + host.name);
}
}
I just added the else clause with the info message.
Try this?
var hosts = vcenter.allHostSystems;
for (var h in hosts) {
var host = hosts[h];
System.log("ESXi Host " + host.name + ":");
// test the name does NOT have mgt in it
if(host.name.indexOf("mgt") == -1)
{
var specAccount = new VcHostAccountSpec();
specAccount.id = username;
specAccount.password = password;
host.configManager.accountManager.updateUser(specAccount);
}
}
@eoinbyrne Thanks! that worked. so another question. I had to test it on each one to verify. is there a way to make my system.log code more intelligent. The workflow skipped my host testmgt01.lab.com, which is what I wanted, but the log didnt really give me an idea if it skipped or change the password on it. here was the log...
Ideally, it would just show me the hosts it actually changed the password on
var hosts = vcenter.allHostSystems;
for (var h in hosts) {
var host = hosts[h];
System.log("ESXi Host " + host.name + ":");
// test the name does NOT have mgt in it
if(host.name.indexOf("mgt") == -1)
{
var specAccount = new VcHostAccountSpec();
specAccount.id = username;
specAccount.password = password;
host.configManager.accountManager.updateUser(specAccount);
}
else
{
System.log("Skipping MGT host " + host.name);
}
}
I just added the else clause with the info message.
Exactly what i needed. thanks again!