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
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
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
Thanks LucD
As always you have the answers