VMware Cloud Community
nareshunik
Enthusiast
Enthusiast
Jump to solution

Need powercli script to list user account in ESXi servers

Need powercli script to list user account in ESXi servers

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

My mistake, try something like this

$user = "root" 
$pswd
= "password"

Get-VMHost
| %{   $esx = Connect-VIServer $_.Name -User $user -Password $pswd
  Get-VMHostAccount -Server $esx |
 
Select @{N="Host";E={$esx.Name}},@{N="Uid";E={$_.ExtensionData.Id}},Id,@{N="Name";E={$_.ExtensionData.FullName}}   Disconnect-VIServer -Server $esx -Confirm:$false
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can use the Get-VMHostAccount cmdlet to list user accounts in ESXi servers.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
nareshunik
Enthusiast
Enthusiast
Jump to solution

can you share me the complete script and also looking for output in this format.

UID    User     Name

Please refer the attachment.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can try

foreach($esx in Get-VMHost){

   Get-VMHostAccount -VMHost $esx |

   Select @{N="Host";E={$esx.Name}},Uid,Id,Name,Description

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

nareshunik
Enthusiast
Enthusiast
Jump to solution

thanks for the script.

But i get the below error message

PowerCLI C:\users\abcd\desktop> & '.\user list in esxi.ps1'
Get-VMHostAccount : A parameter cannot be found that matches parameter name 'VMHost'.
At C:\users\xxxx\desktop\user list in esxi.ps1:2 char:29
+    Get-VMHostAccount -VMHost <<<<  $esx |
    + CategoryInfo          : InvalidArgument: (:) [Get-VMHostAccount], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.
   Host.GetVMHostAccount
Get-VMHostAccount : A parameter cannot be found that matches parameter name 'VMHost'.
At C:\users\xxxx\desktop\user list in esxi.ps1:2 char:29
+    Get-VMHostAccount -VMHost <<<<  $esx |
    + CategoryInfo          : InvalidArgument: (:) [Get-VMHostAccount], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.
   Host.GetVMHostAccount
Get-VMHostAccount : A parameter cannot be found that matches parameter name 'VMHost'.
At C:\users\xxxx\desktop\user list in esxi.ps1:2 char:29
+    Get-VMHostAccount -VMHost <<<<  $esx |
    + CategoryInfo          : InvalidArgument: (:) [Get-VMHostAccount], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.
   Host.GetVMHostAccount
0 Kudos
sakibpavel
Enthusiast
Enthusiast
Jump to solution

Please have a look , here is some script for you..

http://www.kasraeian.com/2012/04/using-vmware-powercli-002-user-accounts/

Sakibpavel 
LucD
Leadership
Leadership
Jump to solution

My mistake, try something like this

$user = "root" 
$pswd
= "password"

Get-VMHost
| %{   $esx = Connect-VIServer $_.Name -User $user -Password $pswd
  Get-VMHostAccount -Server $esx |
 
Select @{N="Host";E={$esx.Name}},@{N="Uid";E={$_.ExtensionData.Id}},Id,@{N="Name";E={$_.ExtensionData.FullName}}   Disconnect-VIServer -Server $esx -Confirm:$false
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pankajkr06
Contributor
Contributor
Jump to solution

Connect-VIServer 1.1.1.1
$esxihosts = Get-VMHost
foreach ($esxihost in $esxihosts)
{
$esxcli = get-esxcli -VMHost $esxihost
$account = $esxcli.system.account.list()
$account | Select @{N="Host";E={$esxihost.Name}},UserId | Export-csv -append -Path C:\temp\acc.csv -NoTypeInformation
}