# PowerCLI Module Installed

<# 

ScriptsbyScott.com

.SYNOPSIS  This process will add a new local account to VMware ESXi host by connecting to the ESXi host. 

.DESCRIPTION     Adds a new account and password and assigns permissions to make the account an adminstrator on the ESXI host.

.EXAMPLE      Run in PowerShell ISE for editing the login credentials and new account informaiton.     

#> 

I always want to have more than just a root account in case someone botches a password reset or loses it.

The script creatres a new account with full rights on the ESXi host.

 

 

PowerShell
Edit|Remove
#Need Values for Login and New Account 
$VMHost="VMHostName" 
 
$Account="NewAccountName" 
 
$Password="YourNewAccountPassword" 
 
$RootPassword="YourrootPassword" 
 
#Load PowerCLI 
Add-PSSnapin VMware.VimAutomation.Core 
 
#Connect to ESXi Host 
Connect-VIServer -Protocol https -Server $VMHost -User root -Password $RootPassword 
 
#Post to Screen  
Write-Host "Creating User For: $Account" 
 
#Creating New Account        
New-VMHostAccount -Id $Account -Password $Password -GrantShellAccess 
        
#Assign Administrator Permission 
$RootFolder = Get-Folder -Name ha-folder-root 
New-VIPermission -Entity $RootFolder -Principal $Account -Role Admin     
 
#Disconnects from ESXi Host  
Disconnect-VIServer  $VMHost -Confirm:$false