Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created January 15, 2019 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vMarkusK/61059bd0eafef84dcbd002d079bc5a97 to your computer and use it in GitHub Desktop.
Save vMarkusK/61059bd0eafef84dcbd002d079bc5a97 to your computer and use it in GitHub Desktop.
VMware ESXi Base Config
function Set-MyESXiOption {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)]
[String] $Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=1)]
[String] $Value
)
process {
$myESXiOption = Get-AdvancedSetting -Entity $VMhost -Name $Name
if ($myESXiOption.Value -ne $Value) {
Write-Host "Setting ESXi Option '$Name' on Host '$($VMhost.Name)' to Value '$Value'"
$myESXiOption | Set-AdvancedSetting -Value $Value -Confirm:$false | Out-Null
}
else {
Write-Debug "ESXi Option '$Name' on Host '$($VMhost.Name)' already has the Value '$Value'"
}
}
}
[array]$NTP = @("192.168.2.1", "192.168.2.2")
[array]$DNS = @("192.168.2.1", "192.168.2.2")
[String]$DomainName = "local.lan"
[String]$ClusterName = "Compute"
[String]$LocalPath = "D:\Image\HPE.zip"
[String]$DepotName = "HP.zip"
[String]$TempDatastoreName = "LOCAL*"
$VMhosts = Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object {$_.ConnectionState -eq "Maintenance"}
foreach ($VMhost in $VMhosts) {
#region: Upload Patch
$Datastore = $VMhost | Get-Datastore -Name $TempDatastoreName
$DatastoreDriveName = "HostStore_" + $VMhost.Name.Split(".")[0]
$Datastore | New-DatastoreDrive -Name $DatastoreDriveName | Out-Null
Copy-DatastoreItem -Item $LocalPath -Destination $($DatastoreDriveName + ":") -Force:$true -Confirm:$false
Remove-PSDrive -Name $DatastoreDriveName
#endregion
#region: Install Host Patch
$HostPath = $Datastore.ExtensionData.Info.Url.remove(0,5) + $DepotName
$esxcli2 = Get-ESXCLI -VMHost $VMhost -V2
$CreateArgs = $esxcli2.software.vib.install.CreateArgs()
$CreateArgs.depot = $HostPath
$InstallResponse = $esxcli2.software.vib.install.Invoke($CreateArgs)
#endregion
#region: Restart Host
if ($InstallResponse.RebootRequired -eq $true) {
Write-Host "Rebooting '$($VMHost.Name)'..."
Write-Host "VIBs Installed:"
$InstallResponse.VIBsInstalled
$VMhost | Restart-VMHost -Confirm:$false | Out-Null
}
else {
Write-Host "No Reboot for '$($VMHost.Name)' required..."
}
#endregion
}
#while(!($VMhosts.Count -eq $(Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object {$_.ConnectionState -eq "Maintenance"}).Count)){
# Start-Sleep 5
# Write-Progress -Activity "Wait for all Hosts are Up and Running" -Status "Wait for Hosts become Online..."
#}
Read-Host "Press Enter to continue..." | Out-Null
foreach ($VMhost in $VMhosts) {
#region: Config NTP
try {
$VMhost | Remove-VMHostNtpServer -NtpServer ($VMhost | Get-VMHostNtpServer) -Confirm:$false
}
catch [System.Exception] {
Write-Warning "Error during removing existing NTP Servers on Host '$($VMhost.Name)'."
}
foreach ($myNTP in $NTP) {
$VMhost | Add-VMHostNtpServer -ntpserver $myNTP -confirm:$False | Out-Null
}
$NTPService = $VMhost | Get-VMHostService | Where-Object {$_.key -eq "ntpd"}
if($NTPService.Running -eq $True){
Stop-VMHostService -HostService $NTPService -Confirm:$false | Out-Null
}
if($NTPService.Policy -ne "on"){
Set-VMHostService -HostService $NTPService -Policy "on" -confirm:$False | Out-Null
}
$HostTimeSystem = Get-View $VMhost.ExtensionData.ConfigManager.DateTimeSystem
$HostTimeSystem.UpdateDateTime([DateTime]::UtcNow)
Start-VMHostService -HostService $NTPService -confirm:$False | Out-Null
#endregion
#region: Configure DNS
Get-VMHostNetwork -VMHost $VMhost | Set-VMHostNetwork -DomainName $DomainName -SearchDomain $DomainName -DNSAddress $DNS -Confirm:$false | Out-Null
#endregion
#region: Configure Static HighPower
try {
$HostView = ($VMhost | Get-View)
(Get-View $HostView.ConfigManager.PowerSystem).ConfigurePowerPolicy(1)
}
catch [System.Exception] {
Write-Warning "Error during Configure Static HighPower on Host '$($VMhost.Name)'."
}
#endregion
#region: Enable SSH and disable SSH Warning
$SSHService = $VMhost | Get-VMHostService | Where-Object {$_.Key -eq 'TSM-SSH'}
if($SSHService.Running -ne $True){
Start-VMHostService -HostService $SSHService -Confirm:$false | Out-Null
}
else {
Write-Debug "SSH Service is already running on Host '$($VMhost.Name)'"
}
if($SSHService.Policy -ne "automatic"){
Set-VMHostService -HostService $SSHService -Policy "Automatic" | Out-Null
}
else {
Write-Debug "SSH Service is already set to Automatic Start on Host '$($VMhost.Name)'"
}
Set-MyESXiOption -Name "UserVars.SuppressShellWarning" -Value "1"
#endregion
#region: Set NetApp NFS Options "https://www.netapp.com/us/media/tr-4597.pdf - Appendix C"
Set-MyESXiOption -Name "Net.TcpipHeapSize" -Value "32"
Set-MyESXiOption -Name "Net.TcpipHeapMax" -Value "512"
Set-MyESXiOption -Name "NFS.MaxVolumes" -Value "256"
Set-MyESXiOption -Name "NFS41.MaxVolumes" -Value "256"
Set-MyESXiOption -Name "NFS.MaxQueueDepth" -Value "64" #Non AFF Systems!
Set-MyESXiOption -Name "NFS.HeartbeatMaxFailures" -Value "10"
Set-MyESXiOption -Name "NFS.HeartbeatFrequency" -Value "12"
Set-MyESXiOption -Name "NFS.HeartbeatTimeout" -Value "5"
#endrefion
#region: Set NetApp VAAI Options "Installing the NetApp® NFS Plug-in 1.1.2 for VMware® VAAI"
Set-MyESXiOption -Name "DataMover.HardwareAcceleratedMove" -Value "1"
Set-MyESXiOption -Name "DataMover.HardwareAcceleratedInit" -Value "1"
#endregion
#Region: Disable iSCSI Adapter (if necessary)
Get-VMHostStorage $VMhost | Set-VMHostStorage -SoftwareIScsiEnabled $false -Confirm:$false | Out-Null
#endregion
#region: Restart Host
$VMhost | Restart-VMHost -Confirm:$false | Out-Null
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment