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:

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