I am trying to find out if this local user exist on my esx servers with this
$accountName = "test"
connect-viserver vc
$esxlist = Get-VMHost
foreach($esx in $esxlist){
$esx = Connect-VIServer -Server $esx -User root -Password "xxxxxx"
get-VMHostAccount -Id $accountName
Disconnect-VIServer -Server $esx -Confirm:$false
}
but keep getting the error
You are probably connected to the vCenter as well (check with $global:defaultViServers).
And since you didn't specify the Server parameter, the cmdlet will take the vCenter connection.
Add the Server parameter on the cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Because that cmdlet does not operate on a vCenter Server level. As the error says, it only functions on an individual host level.
You are probably connected to the vCenter as well (check with $global:defaultViServers).
And since you didn't specify the Server parameter, the cmdlet will take the vCenter connection.
Add the Server parameter on the cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
correct I fixed it after getting my list of hosts and disconnected it from vc
$accountName = "test"
connect-viserver vc
$esxlist = Get-VMHost
disconnect-viserver vc -confirm:$false
foreach($esx in $esxlist){
$esx = Connect-VIServer -Server $esx -User root -Password "xxxxxx"
get-VMHostAccount -Id $accountName
Disconnect-VIServer -Server $esx -Confirm:$false
}