profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Tuesday, December 30, 2014

AIO Powercli Script for Esxi hosts of a vCenter

watch out for the updates on
https://docs.google.com/document/d/19wPb-pUe9dwTzzvwk1O_4ygDNqn0PXN0o0yzf5kahAU/edit?usp=sharing

#AIO Script[tested ok]###
#Start of Script
############################################
#Configure DNS
#Configure NTP,
#Configure Domain
#Configure Dump Collector
#NFS settings
#TCP settings
#VAAI settings
#compiled by: MrAmbiG
############################################
#prompt for vCenter details
$VC = Read-Host “vCenter IP?”
$VCuser = Read-Host “vCenter administrator username?”
$VCpass = Read-Host “vCenter Password?”
#connect to vCenter
Connect-VIServer $VC -User $VCuser -Password $VCpass -SaveCredentials
Write-Verbose "connecting to vCenter" -foregroundcolor Cyan
#prompt for DNS, Domain, Dump Collector, NTP information
$dns1 = read-host "Primary DNS address?"
$dns2 = read-host "Secondary DNS address?"
$ntp1 = read-host "Primary NTP address?"
$ntp2 = read-host "Secondary NTP address?"
$domain = read-host "The Domain name (hint: vce.local)?”
$dump = read-host "Dump Collector's address (hint: VUM IP)?"
$NFSsettings = read-host "If you want to include NFS settings then type 1 or else type 0"
$TCPsettings = read-host "If you want to include TCP settings then type 1 or else type 0"
$VAAIsettings = read-host "If you want to include the VAAI settings then type 1 or else type 0"
#listing hosts
$esxHosts = get-VMHost
#looping the script for each host
foreach ($esx in $esxHosts)
{
Write-Host "Configuring DNS and Domain Name on $esx" -ForegroundColor Magenta
Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domain -SearchDomain $domain -DNSAddress $dns1 , $dns2 -Confirm:$false
Write-Host "Configuring NTP Servers on $esx" -ForegroundColor Green
Add-VMHostNTPServer -NtpServer $ntp1 , $ntp2 -VMHost $esx -Confirm:$false
Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false
Write-Host "Restarting NTP Client on $esx" -ForegroundColor Blue
Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false
Write-Host "Configuring Dump Collector on $esx" -BackgroundColor Blue -ForegroundColor Gray
$esxcli = Get-EsxCli -vmhost $esx
$esxcli.system.coredump.network.set($null,“vmk0",$dump,6500)
$esxcli.system.coredump.network.set(1)
$esxcli.system.coredump.network.get()
}
###NFS Settings
if ($NFSsettings -eq '1')
{
Write-host "Including NFS Settings" -BackgroundColor Blue -ForegroundColor Green
foreach ($esx in $esxHosts)
{
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatMaxFailures -Value 10 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatFrequency -Value 12 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatTimeout -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.MaxVolumes -Value 256 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatTimeout -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name NFS.HeartbeatDelta -Value 5 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name Disk.UseDeviceReset -Value 0 -Confirm:$false
Write-Host -ForegroundColor Green "VAAI Setting Configured  on $esx"
}
}
else
{
Write-host "NFS Settings" -ForegroundColor RED
}
###TCP Settings
if ($TCPsettings -eq '1')
{
Write-host "Including TCP Settings" -BackgroundColor Green -ForegroundColor Gray
foreach ($esx in $esxHosts)
{
Write-Host "Configuring TCP Settings on $esx" -ForegroundColor Magenta
Set-AdvancedSetting -VMHost $esx -Name Net.TcpipHeapSize -Value 32 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name Net.TcpipHeapMax -Value 512 -Confirm:$false
}
}
else
{
Write-host "TCP Settings" -ForegroundColor RED
}
###VAAI Settings
if ($VAAIsettings -eq '1')
{
Write-host "Executing VAAI disable" -ForegroundColor Green
foreach ($esx in $esxHosts)
{
Write-Host -ForegroundColor Yellow "Configuring VAAI Settings on $$esx"
Set-AdvancedSetting -VMHost $esx -Name Disk.UseDeviceReset -Value 0 -Confirm:$false                                   
Set-AdvancedSetting -VMHost $esx -Name DataMover.HardwareAcceleratedMove -Value 0 -Confirm:$false
Set-AdvancedSetting -VMHost $esx -Name DataMover.HardwareAcceleratedInit -Value 0 -Confirm:$false                                        
Set-AdvancedSetting -VMHost $esx -Name VMFS3.HardwareAcceleratedLocking -Value 0 -Confirm:$false
Write-Host -ForegroundColor Green "VAAI Setting Configured  on $esx"
}
}
else
{
Write-host -ForegroundColor RED "Excluding VAAI disable section"
}
#End Of Script

No comments:

Post a Comment