[PowerCLI]: Add Local Administrator Account on ESXi

The is some reason to have local user on ESXi servers even when there is vCenter server for management such as vCenter is inaccessible.

You can use root user for doing operations on ESXi directly but some times, you have to ask someone to do the operations and then you will not have any tacking and all operation will be done by root user.

So create user for trusted colleagues will help you to manage ESXi and track each user about what has he done.

User creation is too easy, you can create users via vSphere Client (C# Client or Web Client) or by run some scripts.

PowerCLI is automation tools for VMware products and you can use it for create more than one users by run few lines of script.

The Script!

You can use the below script for create users and assign proper roles to them but you must change something in the below script and customize it to use:

#Connect to ESXi hosts via root account
$VMHosts="ESXi1 IP/DNS Name","ESXi2 IP/DNS Name",....,"ESXiN IP/DNS Name"
Foreach ($VMHost In $VMHosts)
    Connect-VIServer -Protocol https -Server $VMHost -User root -Password QWERTY
    Foreach ($Account In $Accounts)
        #Create User with Shell Access
        Write-Host "Create User For $Account"
        New-VMHostAccount -Id $Account -Password "Same Password For All Users" -GrantShellAccess
        #Assign Administrator Premission
        $RootFolder = $null
        $RootFolder = Get-Folder -Name ha-folder-root
        New-VIPermission -Entity $RootFolder -Principal $Account -Role Admin
    Disconnect-VIServer $VMHost -Confirm:$false

The above script will create users with Administrator role and each user be able to manage all object under root folder.

Also you can create group for different users and assign the role to the group instead of each user that I’ll publish it in next posts.

Read More on Teimouri.net

Using Client Information in VMware View

VMware Tools Client – Interact with a VM without Network Connectivity

VMware View Pool Entitelement Cleanup

Run ESXi Commands Via PowerShell And SSH

ESXi Command-Line – Part 1

Davoud Teimouri

Davoud Teimouri is as a professional blogger, vExpert 2015/2016/2017/2018/2019, VCA, MCITP. This blog is started with simple posts and now, it has large following readers.

5 Responses

  1. Totie Bash says:

    What is the equivalent if you are connected to vcenter and have a foreach vmhost loop?

  2. Totie Bash says:

    discregard, I just found it https://gist.github.com/jbarber/715238

  3. Totie Bash says:

    actually, link is 2010 old…

  4. Create local account is not supported since version 5.1 via vCenter!

  1. 27/05/2019

    […] [PowerCLI]: Add Local Administrator Account on ESXi […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newsletter and join other subscribers

Holler Box