How to Join ESXi to the Domain and Configure Active Directory Groups for Login via PowerShell

Hi,
Today, I want to configure an ESXi host to join a domain and set up Active Directory groups for logging in to ESXi using domain accounts, all through PowerShell.

Steps:

  1. Run PowerShell as Administrator.

  2. Install VMware PowerCLI by running the following command:

				
					Install-Module VMware.PowerCLI

				
			

3. Connect to vCenter by running the following command:

				
					Connect-VIServer   -Server   <vCenter-Server-IP-or-FQDN>    -user   <your username>

				
			

Replace <vCenter-Server-IP-or-FQDN> with the IP address or FQDN of your vCenter server.

4. Enter your vCenter username and password when prompted.

5. Create a variable to store the ESXi host object. For example:

				
					$ESXiHost = Get-VMHost

				
			

6. Join the ESXi host to the domain using the following command:

				
					$ESXiHost | Get-VMHostAuthentication | Set-VMHostAuthentication -JoinDomain 
"DomainName" -user "Username" -password "password" -Confirm:$false
				
			

Replace:

  • <Domain-Name> with your Active Directory domain name.
  • <Domain-Admin-User> with the username of a domain administrator.
  • <Domain-Admin-Password> with the corresponding password.

7- Add your Active Directory Group that member’s of that group want to login to ESXi Host.

				
					$ESXiHost | Get-AdvancedSetting -Name Config.HostAgent.plugins.hostsvc.esxAdminsGroup | Set-AdvancedSetting -Value "Group Name"
				
			

For Example:

				
					Connect-VIServer -Server vcenter.khoshraftar.com -User administrator@vsphere.local

$ESXiHost = Get-VMHost

$ESXiHost | Get-VMHostAuthentication | Set-VMHostAuthentication -JoinDomain -Domain vmwaredaily.com -user vmwaredaily -password *******  -Confirm:$false

$ESXiHost | Get-AdvancedSetting -Name Config.HostAgent.plugins.hostsvc.esxAdminsGroup | Set-AdvancedSetting -Value  vmwaredailyteam  
				
			

Now, I have a username that is a member of vmwaredailyteam, I can log in with it to ESXi UI.

Finish 🙂

Facebook
Twitter
LinkedIn