tdubb123
Expert
Expert

get-vmhostaccount - the requested operation is only suported when connected directly to esx host

Jump to solution

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

Screen Shot 2018-01-11 at 9.05.27 AM.png

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

View solution in original post

0 Kudos
3 Replies
daphnissov
Immortal
Immortal

Because that cmdlet does not operate on a vCenter Server level. As the error says, it only functions on an individual host level.

0 Kudos
LucD
Leadership
Leadership

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

View solution in original post

0 Kudos
tdubb123
Expert
Expert

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

}

0 Kudos