I'm trying to automate the creation of a Local User in ESXi using the Perl SDK.
I know how to pull a list of users that have permissions from the host.
my $userAccounts = $authorizationMgr->RetrieveAllPermissions;
for my $user (@$userAccounts) {
if ($user->principal eq $add_user) {
# User Exists
if($user->roleId = $add_roleId) {
print "User already exists with correct role, OK\n";
exit 0
} else {
print STDERR "User exists but with wrong roleId.\n";
print STDERR "Requested Role = (".$add_role."), got (";
for(@$roleList) {
if($user->roleId eq $_->roleId) {
print STDERR $_->name.")\n";
}
}
exit 1;
}
}
}
But it is possible for an account to be listed in the Local Users and Groups but have no Permissions assigned.
Does someone know of a way to query if the local account exists? In the vSphere Client when directly connected to a host the Local Users and Groups tab displays this info, I'm lookling to access it in Perl.
Also I've been trying to create a local user account and having no luck
Code:
my $accountManager = Vim::get_view( mo_ref => $service_content->accountManager);
$accountManager->CreateUser( user => { id => 'Inventory2', password => "aBc!56hh", description => "Inventory2" });
Output:
Expected HostAccountSpec for 'user' argument. at (eval 17) line 100
VimService::get_arg_string('HASH(0x1f49c160)', 'user', 'HostAccountSpec') called at (eval 17) line 132
VimService::build_arg_string('ARRAY(0x1f085fc0)', 'HASH(0x1f085f40)') called at (eval 17) line 4163
VimService::CreateUser('VimService=HASH(0x1f214220)', '_this', 'ManagedObjectReference=HASH(0x1f2db240)', 'user', 'HASH(0x1f49c160)') called at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 1693
ViewBase::invoke('HostLocalAccountManager=HASH(0x1f49c760)', 'CreateUser', 'user', 'HASH(0x1f49c160)') called at (eval 36) line 4
HostLocalAccountManagerOperations::CreateUser('HostLocalAccountManager=HASH(0x1f49c760)', 'user', 'HASH(0x1f49c160)') called at vmware_user_add.pl line 151
I suspect I'm making some dumb mistake in calling the method.
Thanks for any help you can give.
-Daniel