VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

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

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
3 Replies
daphnissov
Immortal
Immortal
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

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

}

Reply
0 Kudos