-------------------------------------------
Original Message:
Sent: Nov 08, 2025 08:04 AM
From: a_p_
Subject: User account creation error
Please see whether the below meets your requirements.
André
$cred = Get-Credential -UserName "administrator@vsphere.local" -Message "Enter the vCenter Server admin's credentials."
Connect-VIServer -Server <your-vcenter-server> -Credential $cred
$NewUserCredentials = Get-Credential -UserName "root1" -Message "Enter the new user's credentials."
$vmhosts = Get-VMHost
foreach ($vmhost in $vmhosts) {
Write-Host "Creating $($NewUserCredentials.UserName) on $($vmhost.name) ..."
$esxcli = get-esxcli -vmhost $vmhost -v2
$esxcliArgs = $esxcli.system.account.add.CreateArgs()
$esxcliArgs.id = $NewUserCredentials.UserName
$esxcliArgs.description = "Yet Another user Account"
$esxcliArgs.shellaccess = $false
$esxcliArgs.password = $NewUserCredentials.GetNetworkCredential().Password
$esxcliArgs.passwordconfirmation = $NewUserCredentials.GetNetworkCredential().Password
$esxcliResult = $esxcli.system.account.add.Invoke($esxcliArgs)
$esxcliArgs = $esxcli.system.permission.set.CreateArgs()
$esxcliArgs.id = $NewUserCredentials.UserName
$esxcliArgs.role = "Admin"
$esxcliResult = $esxcli.system.permission.set.Invoke($esxcliArgs)
}
Original Message:
Sent: Nov 07, 2025 06:42 PM
From: Neena Jim
Subject: User account creation error
@LucD / @p0werShelldude
That scripts talk about, connecting the vCenter and then get the root password of all the ESXi hosts and then create a new account. This logic wont work in our environment since all the esxi hosts has its own separate root password. So I am looking for a help to sort the current situation. So I am looking for a script that can connect the vCenter (That has admin privileges) and then create new user account and then add that as part of Admin account. Please let me know if we have a solution for this situation.
Original Message:
Sent: Nov 07, 2025 02:31 PM
From: p0werShelldude
Subject: User account creation error
LucD has answered this cleanly here
https://community.broadcom.com/vmware-cloud-foundation/discussion/creating-local-accounts-on-esx-hosts-with-new-vmhostaccount#bm6216a812-662a-408d-905d-fe450c325498
Original Message:
Sent: Nov 05, 2025 05:26 PM
From: Neena Jim
Subject: User account creation error
I am getting error while running the below commands. Can someone please help?
This is for connecting the vCenter and then create a new user account for each esxi hosts and then add them as part of admin
# Connect to vCenter
$vCenterServer = "your-vcenter.domain.com"
Connect-VIServer -Server $vCenterServer
# Define credentials for the new user
$newUsername = "root1"
$newPassword = "Password123"
# Get all ESXi hosts
$esxiHosts = Get-VMHost
# Create user and assign Admin role
foreach ($host2 in $esxiHosts) {
Write-Host "Processing host: $($host2.Name)"
# Create user
New-VMHostAccount -VMHost $host2 -Id $newUsername -Password $newPassword -Confirm:$false
# Assign Admin role
New-VIPermission -Entity $host2 -Principal $newUsername -Role "Admin" -Propagate:$true
}
Error:

-------------------------------------------