ESXI PowerShell command to Automate ESXI configuration

 # Prompt for vCenter password

$VCCred = Get-Credential

$vCenter = Read-Host "Enter vCenterName"


#$targetVC = 192.168.1.20


#Connect vCenter 

#Connect-VIServer -Server $vCenter -Credential $VCCred


$DataCenter1= Read-Host "Enter Datacenter host"


#$datacenter = Get-Datacenter "Demo_DC"


#Prompt for ESXI

$ESXI = Read-Host "Enter ESXI hostName" 

$ESXICred= Get-Credential


#Connect ESXI host

Connect-VIServer -Server $ESXI -Credential $ESXICred




# Add NTP server details

$NTPServer=Read-Host "Write NTP server details"

#Add-VmHostNtpServer -VMHost $esxi -NtpServer servername

#Add-VMHostNtpServer -VMHost $esxi -NtpServer 192.168.1.16


Add-VMHostNtpServer -VMHost $ESXI -NtpServer $NTPServer

# Create Datastore

$DataStore= Read-Host "Volume Name"

#Storage Device path


$DevicePath= Read-Host "Enter Storage device path"


#New-Datastore -VMHost $ESXI -Name $DataStore -Path mpx.vmhba0:C0:T1:L0 -VMFS -FileSystemVersion 6

New-Datastore -VMHost $ESXI -Name $DataStore -Path $DevicePath -Vmfs -FileSystemVersion 6



# To update Domain name, prefered DNS and SearchDomain


$vmHostNetworkInfo = Get-VmHostNetwork -Host $ESXI


Set-VmHostNetwork -Network $vmHostNetworkInfo -VMKernelGateway 192.168.1.1 -DomainName ads.com -SearchDomain ads.com -DnsAddress 192.168.1.16 -DnsFromDhcp $false




#Add host to vCenter

Add-VMHost -Server $targetVC -Name $ESXI -Location $DataCenter1 -Credential $ESXICred -Force


#Enable Storage IO Control


Set-Datastore -Datastore $DataStore -StorageIOControlEnabled $true

No comments:

Post a Comment

Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...