Created
February 22, 2018 09:34
-
-
Save vMarkusK/d598f63621147db21839a64bb2e8089b to your computer and use it in GitHub Desktop.
This Script Configures ESXi DNS, NTP, SSH, PowerProfile and NetApp Advanced Options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.10.1", "192.168.10.2", "192.168.10.3") | |
[array]$DNS = @("192.168.10.1", "192.168.10.2", "192.168.10.3") | |
[String]$DomainName = "lab.local" | |
[String]$ClusterName = "Compute01" | |
$VMhosts = Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object {$_.ConnectionState -eq "Maintenance"} | |
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