You are here

Managing local ESXi users with PowerCli


Управление локальными пользователя ESXi через PowerCli

In todays short article, I want to show you a couple of examples of managing local Esxi users, with the help of PowerShell - PowerCli and EsxCli.

Connect-VIServer -Server vcenter.some.domain
#for example, we want to make some action on all hosts in the cluster
$hosts=Get-Cluster ClusterName | Get-VMHost
foreach ($vmhost in $hosts){
    $esxcli = Get-EsxCli -VMHost $vmhost.name -V2
    $esxcli.system.account.list.invoke()
    #you can add examples below to that cycle
}
#adding a user
$esxcli = Get-EsxCli -VMHost $vmhost.name -V2
$sAccount = $esxcli.system.account.add.CreateArgs()
$sAccount.Item('description') = 'Test account'
$sAccount.Item('password') = 'verysecretp@ss!@#A'
$sAccount.Item('passwordconfirmation') = 'verysecretp@ss!@#A'
$sAccount.Item('id') = 'test_user'
$esxcli.system.account.add.Invoke($sAccount)

#set a role to the user
$sRole = $esxcli.system.permission.set.CreateArgs()
$sRole.id = 'test_user'
$sRole.role = 'Admin'
$esxcli.system.permission.set.Invoke($sRole)

#update password
$sAccount = $esxcli.system.account.set.CreateArgs()
$sAccount.id = "test_user"
$sAccount.password = "verysecretp@ss!@#A"
$sAccount.passwordconfirmation = "verysecretp@ss!@#A"
$esxcli.system.account.set.Invoke($sAccount)

#remove user
$sAccount = $esxcli.system.account.remove.CreateArgs()
$sAccount.id = "test_user"
$esxcli.system.account.remove.Invoke($sAccount)

 

4 5

Share the article with your friends in social networks, maybe it will be useful to them.


If the article helped you, you can >>thank the author<<