VMware Cloud Community
gman7777
Contributor
Contributor
Jump to solution

Script to add additional user to VMWare host

Hi Everyone,

I retrieved this script to add additional users to a host to avoid using root user. (Thanks LucD)

$node = Connect-VIServer -Server 'cnvm3039' -User root -Password 'Eieio'

New-VMHostAccount -Id 'Nacho' -Password 'EIEI0' -Description 'Tester' -GrantShellAccess:$true -Server $node

New-VIPermission -Entity $node.name -Principal 'Nacho' -Role Admin -Propagate:$true -Server $node

My question, can this be altered to have a answer file for multiple host entries, as apposed to using this for one host.

If so, could someone update this script with that information. I am not a great scripter


Thank You

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

All information is provided in a CSV file.

# Layout of the CSV file

# Server,User,Password,NewUser,NewUserPassword,NewUserDescription,Principal,Role

# cnvm3039,root,Eieio,Nacho,EIEI0,Tester,Nacho,Admin

#

Import-Csv servers.csv -UseCulture | %{

    $node = Connect-VIServer -Server $_.Server -User $_.User -Password $_.Password

    New-VMHostAccount -Id $_.NewUser -Password $_.NewUserPassword -Description $_.NewUserDescription -GrantShellAccess:$true -Server $node

    New-VIPermission -Entity $node.name -Principal $_.Principal -Role $_.Role -Propagate:$true -Server $node

    Disconnect-VIServer -Server $_.Server -Confirm:$false

}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

All information is provided in a CSV file.

# Layout of the CSV file

# Server,User,Password,NewUser,NewUserPassword,NewUserDescription,Principal,Role

# cnvm3039,root,Eieio,Nacho,EIEI0,Tester,Nacho,Admin

#

Import-Csv servers.csv -UseCulture | %{

    $node = Connect-VIServer -Server $_.Server -User $_.User -Password $_.Password

    New-VMHostAccount -Id $_.NewUser -Password $_.NewUserPassword -Description $_.NewUserDescription -GrantShellAccess:$true -Server $node

    New-VIPermission -Entity $node.name -Principal $_.Principal -Role $_.Role -Propagate:$true -Server $node

    Disconnect-VIServer -Server $_.Server -Confirm:$false

}


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

0 Kudos
gman7777
Contributor
Contributor
Jump to solution

Thanks LucD

As always you have the answers

0 Kudos