Good afternoon gods of VMware automation,
I'm currently trying to do some managing of local ESXi user accounts accosts all hosts in vCenter. I found an old thread where LucD had some great code to accomplish what I was looking for, but its not 100% for me.
Thread in question: Need powercli script to create a new local admin account on all ESX and ESXi hosts in the vcenter
I start my script doing a connect-viserver to the vCenter I'm going to be working on, and then in a loop connect-viserver to each host in the inventory (I didn't know you could use connect-viserver directly to a host before this). I'm able to add a user, give it admin role, but then I go to disconnect from that host with disconnect-viserver $vmhost (that $vmhost is a variable that has the current host I'm on in the loop and the same variable i use cor the connect-viserver), but this is where I'm hitting an error. The error looks to say that it is unable to convert the type vmware.vim.automation.vi.core.impl.v1.inventory.vmhostimpl to type vmware.vim.automatoin.vicore.types.v1.viserver.
So what this looks like to me is, while connect-viserver is designed to accept a host object as well as a vCenter object, disconnect-viserver only accepts vCenter objects. If this is accurate you can only connect to a ESXi host and not disconnect. Please tell me I'm just doing something wrong. I think I can work around this by doing a disconnec-viserver with no paramaters to close all connections at the end of each loop iteration, but then'd I'd have to re-establish my vCenter connection after the loop.
Oh and I've also tried something like this
$srv = connect-viserver $vmhost
disconnect-viserver $srv
And that fails with the same error
Ideas?